Archived

This topic is now archived and is closed to further replies.

henksgu

Car game AI?

Recommended Posts

By far the easiest way to create ai for a racing game is create waypoints/splines which the ai cars can follow around the track.

Each waypoint or section of a spline could be associated with a speed, thus telling the ai cars how fast they can go around corners.

For overtaking, there is normally just another spline that goes around the track. If a car wants to overtake, all they have to do is switch over to the overtaking spline.

It really is that simple, and because of it''s simplicity it is probably the most common way of implementing ai in racing games (I could be wrong). However, I doubt that this is the best way to implement racing ai. There are a few serious disadvantages to this kind of environment representation.

Firstly, some poor bastard has to create all the splines/waypoints. It might not sound like a lot of work if you have very simple tracks, but getting the ai cars to fly around the tracks quickly can take a lot of tweaking of splines/waypoints.

Secondly, the spline/waypoints are often static, so your ai cars can''t respond to dynamic obstacles or events that could potentialy change an optimum racing line.

Thirdly, because all your cars are following the same line you will notice a kind of train effect, ie. it looks like all your ai cars are travelling on rails. You might be able to get away with this if you''re doing a formula one type game, but even then it can look very unnatural and be very boring.

Finally, the biggest problem is that you know that this technique feels inadequate and unsatisfying, but thinking of something better is rather difficult.

Another fairly common technique is to define the road''s left and right edges. Using this information you could calculate the optimum racing line beforehand, or at runtime. How you calculate the optimum racing line is the interesting bit. There are allsorts of funky ideas people have used, some more succesfull than others. It''s just a case of being imaginative and having lots of free time.

Check out the link below for an interesting way of learning to drive using reinforcement learning.
http://citeseer.nj.nec.com/pyeatt98learning.html

Of course, there is always RARS for lots of examples of racing ai
http://rars.sourceforge.net/

Hope this helps

Share this post


Link to post
Share on other sites
The AI Wisdom book has a decent section on car racing AI. In one of them, they have an ideal line set up for the cars to travel, plus an overtaking line for them to use when they want to pass.

I haven''t completed the section, but I assume that you could set up each car to have a different personality on how close it wants to stay to either line.

If you do tire wear, you might make it harder for the car to stay close to the inside of the turns, in effect, drifting out on the turns.

I''m sure there are plenty more ideas you could come up with, but this should get you started.

£§

Share this post


Link to post
Share on other sites
I think the AI sould have this basic rules to play a race:

The car should always advance forward

The car always got to be between the borders of the tracks, and should correct his position based on this.

It should know the position of every curve, the optimun angle and the max speed it can be taken and calculate the actual speed based on this info.

It should know the position of every other car/obstacle on sight, and correct its speed/trajectory based on this info.

I really don''t know if it''s posible to calculate all this stuff without slowing down the game. But this are some of the basic rules a human player will follow to win.

Share this post


Link to post
Share on other sites
A simple solution to the ''train effect'' in my opinion is to have more than two splines. For one thing cars that have different characteristics (top speed, maneuverabity, braking etc.) will actually have different ''optimum'' paths to take. So you could have one for each car/car type. but personally what I would go for is to have different splines each with thier own strentghs and weaknesses, and have each car trying to stay as close to the one it thinks is best for itself, and maybe adding a random factor which would encourage it to switch between them.

Also the splines don''t have to be straight lines (for instance on a straight road all that paths are the same) so each spline could have an agreeable width in which the car casn be and still be keeping to schedule.

etc. etc.

Share this post


Link to post
Share on other sites
Just some info:

The racing line is defined as the line that provides the highest average speed around the track (which results in the lowest lap time). It is different for every different car that races on the track and depends on breaking performance, acceleration at different speeds, lateral traction, body roll, etc.

You could design an AI that takes these factors into account and train it to drive a particular track so that it learns how it should handle each corner on each track, just as the human player does. As for passing, you don''t need a specific algorithm for it, just include other vehicles in the list of objects to be avoided, which would include barriers, grass, kitty-litter (sand), etc.

You should definitely check out the RARS site and see what other people have been doing with racing AI.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
quote:
Original post by Timkin
You should definitely check out the RARS site and see what other people have been doing with racing AI.


Nice!
Sorry, what''s RARS?

Share this post


Link to post
Share on other sites
quote:
Original post by henksgu
What is the best car game AI? Is it to set Waypoints or what? Please help me!!!


I wonder how well fuzzy logic might work. It may actually be easier to implement than waypoints/trajectories. I will have to experiment with this because you have made me curious.

Share this post


Link to post
Share on other sites
I think fuzzy logic could work very well.

Also, just to throw in another technique, Colin Mcrae Rally 2 (and probably 3) uses neural nets to get the cars to follow the racing line.




ai-junkie.com

Share this post


Link to post
Share on other sites