Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What kind of AI can you recommend controlling a car in a level where there are hills, sharp turns, straight parts, et cetera?

There is AI in the game already. It uses points on the road to which the car accelerates and when it gets closer, the next points is taken. These points are predefined. The problem is AI-controlled car are not fast enough compared to a human controlled car. The difference is about 14 seconds, so what methods can you recommend to speed up cars?

Increasing just maximum speed of the cars does not help, because then, they do not take turns fast enough. Do you know a solution for this? Do you know a resource where this problem is looked at and solved?

share|improve this question
add comment

2 Answers

You want to look into steering behavious. So that, rather than following points, the AI sees the track and the other cars on it and drives itself based on the information. The site I linked above is a great resource for information and examples.

You might want to check out OpenSteer, a C++ library developed by same author.

There's a C# version too if you're using that: OpenSteerDotNet

That should get you started. If you build and open the OpenSteer demo application (in C++, not sure about .Net), there's a example that shows a car navigating through a path by using... I guess you could call them "feelers." Basically, it has about 10 parallel lines come from the front of the car and are about 3 or 4 times the length of the car. The lines represent the path that the car will travel and can curve if the car is turning. If these lines hit something, the car knows there's something in it's path and it steers in such a way that it will miss it. There's another version that just uses a simple rectangle in front of the car, but it's not as robust as the lines.

Here's an image of what I'm describing: OpenSteer Demo Car Example

share|improve this answer
    
This is really interesting, +1! –  akled Mar 4 '12 at 21:47
    
one needs to take into account if the algorithm is too complicated, it can affect the framerate –  Aftershock Mar 25 '12 at 11:03
    
@Aftershock - Yes, of course. That goes without saying for any kind of AI you add to your game. However, you can't really hypothesize on whether or not it will slow your game down without at least trying it. Also, there are lots of options when it comes to optimizing it. For example, you could use fewer "feelers" or, rather than checking every frame, you could do a few checks on one frame, a few on another and then the final checks on the third frame or do the whole thing every 10 frames or something like that. No one says you can't modify it to fit your needs! :-) –  Richard Marskell - Drackir Mar 25 '12 at 21:10
add comment

You can make the AI-controlled cars turn faster, you make the computer slow down while turning and speed up while going in a straight line. Don't be afraid to make the AI cheat, as long as the player doesn't notice.

share|improve this answer
    
I strongly disagree: if the computer looks like the player, it would better follow the same rules too. Making it cheat might be necessary in some situations, but: (1) avoid it if you can, and (2) you'd better also show in the game it is different, such as giving the car a different model, so you can expect a different behaviour. –  Lohoris Mar 4 '12 at 9:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.