4
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ This is really interesting, +1! \$\endgroup\$
    – jcora
    Commented Mar 4, 2012 at 21:47
  • \$\begingroup\$ one needs to take into account if the algorithm is too complicated, it can affect the framerate \$\endgroup\$
    – Aftershock
    Commented Mar 25, 2012 at 11:03
  • \$\begingroup\$ @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! :-) \$\endgroup\$ Commented Mar 25, 2012 at 21:10
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – o0'.
    Commented Mar 4, 2012 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .