cars ai

Blitz3D Forums/Blitz3D Programming/cars ai

Charrua(Posted 2010) [#1]
Hi

I have been playing with beziers, jv-ode, cars, tracks and some basic ai for them.

http://sites.google.com/site/odriozolajuanignacio/carsAI.zip

there are 2 executables, one for race and other for edit the tracks to play with.

some screen shoots:





the tracks definition file:
http://sites.google.com/site/odriozolajuanignacio/tracks.dat

the race.bb source:
http://sites.google.com/site/odriozolajuanignacio/autos_v_08.bb

the EditTrack source:
http://sites.google.com/site/odriozolajuanignacio/EditTrack2.bb

i'm not an expert on this subjects but my intention is to start a thread to talk about race ai, cars ai and the like.

best regards

Juan


_PJ_(Posted 2010) [#2]
I 'm certainly no expert either, and forgive me for not yet looking over your code, but jsut as a general approach, I would make use of some form of waypoints along the track which the AI cars would aim for, with perhaps some preventative code which ensures they don't cut across the corners bt try to stay on the track.

What's more 'interesting', perhaps, is dealing with more specific AI instances with regards to how the cars deal with racing. For example, how do they deal with overtaking, or when needing to decelerate for turns etc.
I don't have any specific suggestions for this, but definitely worth consideration.

Lastly, with all that taken into account, the general 'problem' would be that all the AI cars behave in a very similar way. This is something that I personally feel is a little 'outdated' when it comes to racing games, and that AI cars (drivers) ought to have more distinct 'personalities'.
Some of this distinctiveness may come from the car itself, i.e. different specs. But it's nice to see, say, one particular car (driver) will race more aggressively or something.


Charrua(Posted 2010) [#3]
i agree with all you say.

at this stage, the ai inplemented shoul be called a (with out i)
cars all behave equal trying to stay on the road at a rasonable speed, and trying to detect each other to race with out hundreds of collisions between them.

my intention is not to talk about the code, but, with suggestions could be grow time to time.

there are lots of different aproaches:
how to define the track is as i think the firs one. How much info should we must know in advance about the specific shape of the track?. All that we know in advance isn't needed to calculate at run time..

i started with this and i'm trying to get a code for the one i choose, probably in the middle, i discard this track for a better one.

does any one has yet a better aproach?

thank's

Juan


Blitzplotter(Posted 2010) [#4]
I am trying this out now, will let you know what I think soon ish, wow it even has multiple camera mode!

I hope you do not mind, I am threading in joypad support, however it may take a little time, I really need to code for my University studies - which is no way near as much fun as doing this!


Blitzplotter(Posted 2010) [#5]
Here you go, joypad support - please note you need to generate a separate joypad.cfg file for this code to detect a typical joypad - the code for the joypad.cfg file is available at the bottom of the code listing. I auto generated my .cfg file from a utility a long while back from the Blitz forums, I cannot seem to locate it now..

Regards, BP.




Charrua(Posted 2010) [#6]
thx for the update, i haven't one, but, when i grow probably buy one!

Juan

(there is still to much to do with the cars ai source... it has some goods and some bads)


Dabhand(Posted 2010) [#7]

but, when i grow probably buy one!



What are you, a tomato! :D

Seriously though, nice work, and a very generous share for the community me thinks! ;)

Dabz


Blitzplotter(Posted 2010) [#8]
Hi Charrua, would you mind telling me which version of B3D you are using ? The only reason is I could not compile your track source code until I commented out ParentEntity:

http://www.blitzbasic.com/Community/posts.php?topic=90321#1026451

Regards - BP.


Charrua(Posted 2010) [#9]
hi, i'm using 1.98

as yasha said is part of FastExtension, and i didn't know it!

the idea is that if you Picked a ControlPoint you have it's entitys handle via PickedEntity(), then, as control points has as parent the tTrackPoint\Entity then using ParentEntity we have the parent handle and look for the tTrackObject where control point belongs, any way GetTrackPoint do a search so, modify GetTrackPoint to search either for a match either Entity or cp1. GetTrackPoint must return the tTrackPoint object that the WayPoint or ControlPoint belongs:

Function GetTrackPoint.tTrackPoints(Entity)
	Local tp.tTrackPoints
	For tp.tTrackPoints = Each tTrackPoints
		If (tp\Entity = entity) or (tp\cp1 = entity) Then Return tp
	Next
	Return Null
End Function


change the line that uses ParentEntity to:

If GetTrackPointNumber(Picked)<>-1 Then
	AdjustNeighborsCp(GetTrackPoint(Picked))
Else
	;AdjustCP(GetTrackPoint(ParentEntity(Picked)))
	AdjustCP(GetTrackPoint(Picked))
End If



Juan


Blitzplotter(Posted 2010) [#10]
Thanks Juan, I appreciate the description of why as well.

I am considering the possibility of super imposing the track editor on top of some 3D scenery, I'll confess and admit I have not analysed the code enough to know if this is possible, but I'll let you know how I fair.


Charrua(Posted 2010) [#11]
the waypoints are 3D but only 2d in my app.

The bezier interpolate is 3d too, but the Grey Cubes (tSteps\Sector) are only rotated in the Y axis.

See the RedrawTrack, the sentence: RotateEntity(p\Sector,0,EntityYaw(p\Entity),0) do only Y alignement, probably but not tested, if you introduce EntityPitch and EntityRoll the Sectors follow the 3d bezier interpolation.

i have no idea on how you will match your scenary with a series of waypoints that folow certain interpolation, say, if you scenary didn't follow the same interpolation they will be missplaced. Hope you understand what is in my mind. My english is very poor to express my self. sorry

Juan


Blitzplotter(Posted 2012) [#12]
Charrua, have managed to get back to this (wow, its been 2 years already) - having some fun with your bezier interpolate code - the 'jist' of it is creating waypoints for some 'runners' to follow - the speed of the runners between each waypoint will be modified on a waypoint by waypoint basis.

The data for the waypoints & the speed will be gathered by a Global Positioning Satellite training device, the goal being a runner can compare his runs in 'realtime' after the events seeing where and how far appart he managed to perform in different training runs.

[Edit] - I have FastEntity now as well....

Cheers - BP.

Last edited 2012


RemiD(Posted 2012) [#13]
Interesting demo :)




What's more 'interesting', perhaps, is dealing with more specific AI instances with regards to how the cars deal with racing. For example, how do they deal with overtaking, or when needing to decelerate for turns etc.
I don't have any specific suggestions for this, but definitely worth consideration.

Lastly, with all that taken into account, the general 'problem' would be that all the AI cars behave in a very similar way. This is something that I personally feel is a little 'outdated' when it comes to racing games, and that AI cars (drivers) ought to have more distinct 'personalities'.



I have thought about that and i have found a possible solution.
It uses a mix of AI and pre recorded path with waypoints.

Let me explain the theory :
first, i play on the track several times, and my program records the waypoints and my time.
In each replay data there are waypoints data, and time data.

With this, when i play with others vehicles, the program selects some of the replays datas and use it to create the others vehicles pre recorded paths.

When a vehicle is in collision with an other vehicle, the vehicle goes into AI mode and behave in certain ways in order to avoid the others vehicles, then it goes towards the nearest waypoint there is and follows the precalculated path.

The advantages of such a system is that the AI will always appear random and will sometimes be smart and sometimes do errors. And they will have a human behavior.

Also the combination of different precalculated paths can provoke interesting behaviors when 2 vehicles come into collision.

The hardest part will be to program the AI just after the collision.

What do you think ?

Last edited 2012


Charrua(Posted 2012) [#14]
@bp
yep lot of time, currently i haven't had time to play with blitz and/or ode (too much work :)

@RemiD
isn't a bad idea. but (always a but) i think that ai must be used for cars to evade collisions (normally is one of the goals not to suicide)
When you say: prerecorded you mean a car moved by blitz and not by the physics engine?


There are many aproaches (as always) one could be that cars could be managed by blitz most of the time and in case of collisions then jv_ode do it's job to reach a more realistic behavior. Say not a 100% physics simulaton (like the code i posted), instead a balance between physics simulation and some mixture of blitz managed, physics when needed, pre recorded paths and AI.


Juan


RemiD(Posted 2012) [#15]
Charrua>>
Yes there are 2 modes :
When there is no collision, the first mode is used, a kind of replay of a prerecorded path without physics and without ai.
After a collision, the second mode is used and the ai tries to recover from the collision or tries to damage the other vehicle.
Then after a while, the vehicle searches and goes towards the nearest waypoint of the pre recorded path and follows the path again.

Also what is good with this system is that you can record each path of a user when he plays and add it to the pre recorded paths for this specific circuit.

I would keep only the paths where the user does not leave the road and a mix of bad times and good times so that there are bad npcs and good npcs.

Depending on the kind of gameplay you want, you can use the same concepts to trigger a specific behavior of a npc.

For example let's say you do a racing game where the vehicles want to avoid collisions, then you can check the distance between each vehicle and each others vehicle and if a vehicle is too close, then you can trigger a behavior to avoid the collision by making the vehicle turn at the oposite of the other vehicle during the time the other vehicle is far enough. Then the vehicle can follow its path again.

At the contrary if you do a racing game where the vehicles want to provoke collisions, if a vehicle is too close, you can make the vehicle brake or turn right or turn left so that it annoys the other vehicle, then when the other vehicle is far enough, the vehicle can follow its path again.

Last edited 2012


Blitzplotter(Posted 2012) [#16]
Charrua, yeah my time is somewhat tight as well, i aim to get there in the end!


Slomas(Posted 2012) [#17]
Hi Juan,

I wrestled with racecar AI a while ago and ended up giving up on waypoints for something which worked better- for me anyway

That is to approach it as a driver would- 'looking' at the actual track ahead.
Two 'feelers' or 'eyes' are parented to the car- sent ahead a distance relative to the car's speed- and left & right to find the track edge (using LinePick from the eye/cube objects in the air in this pic)

This returns upcoming direction & rate of turn, track tilt, rise/fall, width etc.. i.e. the track edges themselves represent continuous waypoints -
the nice thing is- there doesn't have to be any standard width etc to conform to- the AI will work with whatever it sees.

Allowing the AI car to experiment with its own parameters for controlling and responding to it's 'eyes' for the fasted time- lets it find the best technique for the track

I think Vorderman made a more complete version of this stunt car game-
he'd be a good person to ask?