Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / plz help me with my racing AI

Author
Message
phukol
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location:
Posted: 9th Jan 2004 19:16
Im using Matedit 1.6b together with DBC. I tried to follow the tutorials posted on this site which makes use of HOTSPOT (e.g. Limit Rush) but i want to make use of MatEdit's zone instead so that the enemy racer will only follow the path designated as zone 1 or zone 2, i manage to make it follow throught the zone in a staight path but the problem is "it is not able to turn left or right when i programmed it to(preety stupid of me)". Can anyone suggest what's wrong? here is the code:

`-----------------------------------
`racing artificial intelligence
`-----------------------------------
function control_player(id)

X=object position x(id)
Z=object position z(id)+36.5
Zone=CheckZone(X,Z)

xPos#=object position x(id)
zPos#=object position z(id)
yAng=object angle y(id)

if zone=1 or zone=2
forward=1
left=0
right=0
backward=0
else

X2=object position x(id)+15
Z2=object position z(id)
Zone2=CheckZone(X2,Z2)
if zone2=1 or zone2=2
` targetXPos=X2
`targetZPos=Z2
right=1
else
` targetXPos=object position x(id)-15
` targetZPos=object position z(id)
left=1
endif

`angle#=atanfull(targetXPos-xPos#,targetZPos-zPos#)-yAng

`work out direction to turn
`if angle#<-180
` left=1
`else
` right=1
endif
move_player(id,forward, backward, left, right)

sorry if my code is so crude, im really just starting in coding. i've included the other code i used and made them a remark.

phukol
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Jan 2004 04:00
What you want is to have variables that hold all of the destination data, and the current position data.

ie;



You then need to specify which destination to use, something like;




Then, you check to see if the destination and the position are about the same, if not, move the object.

ie;



All together, that becomes;



In that fashion, you are directing the object at it's destination, checking if it is in the general vicinity ( ie, either exactly at the loaction, or just near it ) then if it is, you change it's way point, if it isn't, you move it untill it is.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
phukol
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location:
Posted: 11th Jan 2004 16:28
thx pal! il try the code and tell you what happened! god bless!

phukol
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 12th Jan 2004 04:02
Hey, I'm just doing my job... Even though I don't get paid for it, still, lol.

Glad To Have Helped.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
phukol
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location:
Posted: 24th Jan 2004 14:06
jezz it's me, i modified my code but i still have had trouble with the car turning around specified tiles that i marked as zone=1 using Matedit. is it ok if i send it to your e-mail and give me a hint as to what is the problem. i just dont have anyone to help me figure out what is troubling my code.

phukol
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Jan 2004 09:21
You can email me if you wish ( but make sure "DB" or "Dark Basic" or somethign like that is in the subject line ).

But, I don't use MatEdit, so I don't know how to set up "Zones" or how to use them.

Using my method of waypoints and arrays, is a much better way ( and is probably the way that MatEdit set's up the "Zones" ).

What you do for my code, is you set up the waypoints in the array, then, if all the "racers" are following the same path, that means they can al use the single array, and you just For...Next loop it to check for each car's position, but, instead of using "dest(1,0) = 1" to see which way point it's up to, each "racer" would have it's own check.

That should work for any kind of movement you have.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
phukol
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location:
Posted: 28th Jan 2004 08:04
thx

phukol

Login to post a reply

Server time is: 2025-05-22 12:01:22
Your offset time is: 2025-05-22 12:01:22