Skip to main content
GameDev.net gamedev.net
🔒 Locked

AI in a racing game?

Started by jakssdsfs Mar 31, 2006 at 3:03 AM 16 replies 6k views
Original Post
jakssdsfs
jakssdsfs
Hello.. I've been working on a projekt with some friends in DirectX9 and C++, we have very good structure (Scene Graph) and everything is very dynamic (and with own engine). But the area we don't have any experience in is AI and how to apply the AI to the racing opponents. We have right now a very simple path system that makes the opponent to travel against a position (on the map) and when it has arrived to continues to the next one. Very simple AI, but how can we make the opponents "smarter" and more advanced? Any suggestions?
Game Developer...
averisk
averisk
You could use a neural network to determine how much forward thrust or turning to apply. I'm doing some research in this area and have found some success

Nice thing about doing this is that you can train different networks to drive in different ways (ie. aggressive, careful, etc.) and so you can have opponents with different styles.

I'm doing it out of interest, I don't think it's really practical or necessary to use neural networks for games most of the time.
tjweb92
tjweb92
I don't think you need to much AI here.
Try a balance system this will take your car X and theres Y and when one is here the other is there

like this
Y = X*-1

You will need to change this to your setup. for this to work make 0 the center of the track and - will be off to the left and + will be right. It will make them do the oposite of what you do. If you want somthing better PM me and i will give you an AI code.

And if you need somthing like a drafing (when they stay behind you to reduce wind resistance) then use somthing like this to calculate drafting:
Yw = enemy car width
Xw = your car width
Yh = enemy car height
Xh = your car height
D = Inches to right
S = speed
A= Aceleration (must be set to start and output will be new aceleration)
(change x to set resistance level raising number will lower resistance)
X=100
Dw=Xy-Yw
Dh=Xh-Yh
Dv=Dh*Dw
Rv=Dv/2
Lv=Dv/2
Rv=Rv+D
Lv=Lv-D
V=Lv+Rv
R=S*V
A= A-(R/X)
Check my forus at http://s14.invisionfree.com/tsoftor http://tjsoftware.tk
jakssdsfs
jakssdsfs
Yes, I was thinking of little more advanced than pathfinding (following nodes on map).

Your balance system sounds interesting, I will pm you for some little more information (as you said).

thanks for all the replies.
Game Developer...
Steadtler
Steadtler
How about steering behaviors?
jakssdsfs
jakssdsfs
what about it?
Right now I only have some nodes on a map and it interpolates a vector between the nodes, and the AI-cars are just going straight after that line (some delay when turning (depending on speed) which make it slide in turns), but it doesn't know how fast it should drive to stay on track, if I don't adjust in in the node manually. But I prefer not :)

That is all I got unfortunally, so I don't have any big clues how to do the rest.
Make the AI-cars figure out right speed in the curve/road, how it will react on impact with human-driver (if its just going to turn back to previous position as smooth as possible).

I can also tell that the game includes weapons on vehicle so that will also be a AI-issue but the driving is higher priority than weapons.
And that AI-cars don't just follow each other, that they will try to push out the other drivers of the road or just trying to get passed the leader.

All kind of AI is needed, all kind of help is helpfull.
Game Developer...
Steadtler
Steadtler
I meant depending on the complexity of your racing game, steering behaviors might be a very elegant solution.

I see only three steerings necessary:

a-Move forward
b-Avoid collision
c-Negociate Curve

-Move forward push your AI in doing loops the fastest possible
-Avoid collision make your AI avoid other cars
-Negociate curves make your AI brake to the right speed before entering curves.

I think each of these behaviors would be simple to implement.
a) is straightforward.
There is already tons of ressource on how to do b) in AI books/tutorials.
c) would be a simple calculation depending on the car velocity vector, projected position when entering the curve and the configuration of the curve.

Note that a) should push the car to take curve by the inside.

edit: ok I didnt read about the weapons. They can be added to the AI by adding more steering behaviors. Try to keep each of them simple, and it should work great.
haphazardlynamed
haphazardlynamed
depending on the detail of your physics this may or may not work
but I may as well toss the 'PIT Manuever' out...
http://en.wikipedia.org/wiki/PIT_maneuver
basically it lets you force another car off the road...
might be fun to have as an AI behaviour, tho if every single car was trying it constantly things would get wierd...
jakssdsfs
jakssdsfs
Great tips, thanks,

just one follow question to both of you.

You have any examples/sources of little more how the techniques work?

Steadtler, sounds like you have some experience in these things, I understand a bit of what you trying to say, but you know some source I can get more "hands on"-information?
Beacuse how it will move forward is very easy I agree, but avoid collision in a good way, I have no good experience about it so there I would like some more information if you got any, please.
(or where I can get the information I need)

great replys, thank you for the help
Game Developer...
Steadtler
Steadtler
Hum check out the book "Programming Game AI by Example" there is a good chapter on steering behavior including collision avoidance (with source!).

If not an option, Google "I feel lucky" gave this:

http://www.red3d.com/cwr/steer/

and it looks like a GREAT explanation.

check this out:

http://www.red3d.com/cwr/steer/PathFollow.html

hum... Im bookmarking that.
Cubed3
Cubed3
Check this out

http://www.gamasutra.com/features/20051213/villiers_01.shtml
jakssdsfs
jakssdsfs
hmm, PSO algoritm sounds very intresting, will check that out, thank you
Game Developer...
jakssdsfs
jakssdsfs
I looked at PSO algorithm and "http://www.red3d.com/cwr/steer/PathFollow.html" and the "http://en.wikipedia.org/wiki/PIT_maneuver"...
The only problem is that all is theory, I understand a small part about how it should work, but don't really know how to "evalutate" things, they all say evaluate which node to goto and what to do, but I'm not sure how to evaluate the nodes, I know their position and can count where to turn but how to have best speed to take the turn the best and such things, that PSO and so should fix. Just want to see some code/functions/calculations how to evaluate the nodes to implement it.

anyone got some code/pseldo how it works?
Game Developer...
averisk
averisk
Quote:
Original post by Steadtler
Hum check out the book "Programming Game AI by Example" there is a good chapter on steering behavior including collision avoidance (with source!).

If not an option, Google "I feel lucky" gave this:

http://www.red3d.com/cwr/steer/

and it looks like a GREAT explanation.

check this out:

http://www.red3d.com/cwr/steer/PathFollow.html

hum... Im bookmarking that.


FYI the examples on that site look like a direct implementation from the book you mentioned
Steadtler
Steadtler
Quote:
Original post by averisk

FYI the examples on that site look like a direct implementation from the book you mentioned


I dont think it is. The author of the site seems to have its own steering behavior library that predates the book.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.