The quest for a better racing AI system

As I get closer to implementing the racing AI for my game, it stuck me that most racing AI systems are not really that intelligent all. It seems like every racing AI system wants you to drop waypoints on the track, and …

“Wait. Waypoints? Why do you need waypoints?”

“So your bots know where to go on your track.”

“You mean the AI can’t figure out how to get around the track by itself?”

“Well Duh! Of course not! How is the AI suppose to know where the car is suppose to go? Do you think it figures these things out by itself? You need to tell the cars where to go.”

I’m sure some of you are scratching your head and saying the same thing to yourself as well.

Quite a number of years ago, I played a racing game where you designed your own tracks, setup up a few checkpoints [more for keeping track of laps and course cutting], and then drove a few laps to provide a basic path for the track. Then you would create AI cars that would run X number of laps around the track, and each AI car figured out how to drive around the track by itself! As the cars drove around the track, the AI would figure out how to best take each turn, when to brake, and when to accelerate. Imagine that! The only problem is, the AI would always out perform the player. The player would have to drive a perfect race AND beat the fastest AI car. Well that’s no fun for the player who is just starting out, or who isn’t or will never be perfect. And in real life, people race against others in the same “class” - racing against people who are at the same skill level.

So what makes a good racing AI system?

IMO…

  1. The AI cars can figure out how to get around the track in advance of a race without waypoints.

  2. The AI can be adjusted to match the player’s skill level, so that the player has an even chance of winning a race.

  3. The AI makes mistakes. Most AI systems already have mistakes factored into them, some better than others.

  4. The AI doesn’t just pass anywhere on the track. This is a personal pet peeve of mine.

  5. AI cars have a “personality” that the player can factor into their racing strategy. In other words, the player isn’t just racing against a bot with a script. The player is racing against a specific driver that is somewhat predictable.

  6. … and what else?

Got any ideas? Have any pet peeves about racing AI that you absolutely hate or would like to see fixed? Have you already seen this type of AI in a racing game?

From what I’ve read so far, neural networks are the key. I’ve used all but one of the existing AI solutions for Unity, and they’re all based from the Gotow waypoint script. I believe neural networks and adaptive learning is what’s going to make racing AI more fun.

Rather than waypoints I’d want to define the race-line for a track, which I’d think would be pretty easy to calculate in code.

Based on the properties of the car you should then be able to calculate the optimal speed for any point on the race line.

In addition to that, you want to take dynamic “obstructions” (ie: debris, or other racers) into account to modify any particular agent’s version of the race line.

The skill and personality of an agent is then built into the latter two parts of that. A skilled AI is one which sticks very close to the optimal speed on the race line and is able to get back to the race line very quickly when it is forced away from it, where an unskilled one deviates from the optimal speed (going too slow, or losing control by going too fast) and takes longer to return to the line. An aggressive AI will happily drive through debris, get close to and possibly even bump or nudge other cars, where a less aggressive one will be more careful, and so on and so forth.

This is of course assuming the kind of racing game where the line is important. If you’re making something that’s arcadey to the point where the race line is of little relevance (eg: Burnout Paradise) then it won’t really help a lot, as in those games having a bunch of cars driving a perfect (but irrelevant) line isn’t actually any fun.

  1. Yes and no. Avoiding waypoints for the sake of it is just making extra work for yourself, though it depends on what you mean by and use of waypoints. They are still very useful as a shortcut to getting your AI to learn tracks, but it doesn’t mean they have to travel ‘through’ the waypoint. Afterall there are generally only a few ‘perfect’ lines around a track, depending on your driving style and if you are currently trying to overtake (getting a better position).

  2. Yes but see 3.

  3. THIS - I still can’t understand why most serious racing games still don’t ensure their AI can make mistakes. I’m not a bad driver in racing games (e.g. Forza), I understand ‘good racing lines’ and can even tweak a car half way decent. However against ‘perfect’ AI I never win, becuase i’m just to prone to making mistakes, normally in out braking myself.

Racing would be so much more fun if the AI had an equivalent chance of making the same mistakes as I do, especially if i’m behind them and trying to over-take (i.e. pressuring them into a forced error). Thats not to say all AI skill levels have to make mistakes, or that AI drivers have to make mistakes randomly, just occasionally and ideally tied into external factors, such as they make a mistake when trying to overtake, or when i’m harrasing them or perhaps more prone to mistakes on the last lap or two (which is normaly when I tend to lose it :wink: ).

  1. Not sure i’d arbitrarily ensure they can’t overtake anywhere on track, you can pretty much be over-taken anywhere especially if you make a mistake, or sometimes a slight error (getting on the gas a little late out of a corner). However I’m assuming you are implementing as realsitic a simulation as possible, which in itself should limit the points where over-taking can be achieved.

  2. Personality is good. Personally I quite like it if a driver reacts to the players bad driving. I.e. the more times you collide into them, the less respect they have for you and the more likely they might bump your car to gain position. Not running you off the road, just giving as good as you get.

  3. I’m not really sure there is much more you can do, without moving away from the realism of a sim. Most RL racing i’ve seen all the drivers are incredibly careful about how they drive, what risks to take. The only real difference between them comes down to overall driving skill (sometimes affected by conditions on track) and from very small degrees of difference in how aggressive they might be or risks they might take, but even then its usually very ‘controlled’.

Although I understand the concept behind neural networks, it’s not something I know how to translate into code. It’s definitely something to look into.

I’m thinking exactly along these lines. :slight_smile:

Criterion Games has ruined the NFS series to the point that I won’t play Hot Pursuit or Most Wanted, both of which we have in the house - so “arcadey” is definitely out!

Criterion aren’t the guys who turned Need for Speed arcadey, that’s been happening for a long time. And arcade games can be awesome, and of studios currently making arcade racers Criterion are in fact my favourite by a long shot. Burnout Paradise is one of my favourites. Hot Pursuit is fun, though I don’t think I like it as much as Paradise. And I’m very much looking forward to Most Wanted, hoping it’s a mixture of the two.

So I have to disagree that Need for Speed was ruined by Criterion - partly because I don’t think it’s ruined, and partly because if it is Criterion certainly didn’t do it.

But also… all “Need for Speed” really is as a brand is “racing games produced by EA”. Shift, for instance, really doesn’t have much in common with the other NFS titles.

Very true. In real races, cars more than often follow each other like a train around a track following the proper line. It’s variances in driver consistency that put them off the driving line - and I think it’s important to capture some of that in a game. In practice, I would have to write it such that each AI establishes it’s own waypoints around the track vs following “perfect” waypoints a person creates on a map.

Exactly.

Because AI can drive “perfectly”, they just squeeze in where the car fits, whereas a real person would be more careful as you indicate below. I’ve played games where if you go slightly wide, the AI threads the needle and just blows past you as if your car wasn’t there.

This is a great idea.

I think having the AI prioritize what it should focus on should help in this area. i.e. focus on avoiding a collision vs passing vs maintaining the racing should make it more realistic. It’s more like what a person would do.

Ha ha. Okay. We can agree to disagree.

Like you said, arcade racers can be fun, and I do enjoy playing them, it’s just that I played the original HP and MW, and I like the original titles much better than I do these new titles made by CG. That’s why I said what I did.

I had some time today to try out a different technique to detect and react to opponents on a track. In my test scene, the agents are four cubes racing along the inside edge of a square.

The agent determines when to turn based on it’s preset speed and it’s own experience turning without hitting the wall. Raycasting is used to gauge distance to the wall and if the cube should continue to turn. Rigidbody rotation is limited to the Y axis.

Raycasting is not used to detect opponents. When a cube “detects” another cube in front of it, it will slow down, but it may end up bumping the other cube, drafting behind the other cube or passing the other cube. A cube may knock another cube outside of the racing area, or even drive itself outside of the racing area. If either of those events occur, the cube will go back to it’s spawn point and start racing again.

Webplayer link: http://dl.dropbox.com/u/25954755/aiTest01/aiTest01.html

What exactly is the “detection” process?

Are the cubes attempting to learn how to avoid future collisions?

I imagine raycasting would still be needed to detect the walls, unless they can “see” or “feel” what’s around them.

I’m not quite ready to share this info yet. Am I on the verge of some major paradigm shift in the way racing AI works that will change racing AI forever? I doubt it. :wink:

Yes, this is the next step. Parameters will be adjusted dynamically just like how the cubes try to avoid going outside of the track area.

Raycasting is still required for the agent to learn how to drive around the track. As you indicate, the agents are “feeling” their way around the track and adjust their path accordingly.

This was just a simple test. It needs a lot more research and refinement. I’m quite surprised at the results and I think I may be onto something… or not. lol

Thanks for your questions. :slight_smile:

Looks very interesting, loving the motion you have with the cubes. Perfect for your RC Racing Sim. :slight_smile:

I’ve tried this before. Good for relatively flat surfaces. You’ll also need many more raycasts and layers for that matter it tweak it.