Designing racing game AI

When you have other cars driving on the track, you can make them go from the start to finish by tracking to positions on the track with incrementing numbers. But, this forces them to follow a single path, which means they would drive in single file.

I can use pathfinding (using a nodemesh) but this might use a lot of CPU overhead to calculate the next move of each of 30 cars each frame. Do you think this is a decent solution for a mobile racing game?

use some local logic, on the object rather than pathfinding. Think of what the player thinks:
corner? slow down, turn to try and face the “exit” of the turn.
straight? accelerate like hell
obstacle? swerve to avoid depending on what’s on either side of the obstacle
make all of this apply something to the physics model, like a steering or engine force, to make them more like the player, rather than a car who goes round the track using some strict, robotic path and velocities.
Add any other situations can think of.
I put the bove into a context that should make it easily doable with the existing sensors and perhaps some simple scripting required.

But how would you make them not crash into each other? I guess there could be some kind of distance check for each car. Maybe I could combine pathfinding with your AI ideas.

I’ve made a waypoint based AI using Mmph! as a base. Find attached what I have done so far (have a look for my posts too). The biggest problem you will get is that each node will require to be done in logic bricks (so 50 waypoints is 50 stacked logic bricks…nasty!!). What Haker23 describes can also be done (I have many, many tests of this approach) and it is difficult to get right as the sensors create a ‘reactionary’ AI - in that I mean the AI will not steer intelligently (think of a blind man with a cane tapping around…hits a wall…turns left a bit…etc). In a racing game that is impractical at high speed. A mixed approach would be great on paper, but it would involve states and its a minefield of logical errors. I could type in a veritable essay (I’ve been working on a logic based AI for months). If you want I can list all the approaches I have done (its a looooong list though!)


AI_VER3ex.blend (1010 KB)

You can combine some steering behaviours to make some simple race AI.

The inventor of boids has an overview of several steering behviours, although you should check out the crowd path following one in particular.

Hacker 23 put it perfectly.
define some simple logic. same goes for avoiding other cars, this can be done using a simple ray or radar sensor. just have the car check its left,front, and right sides, if it sees a car to its left and theres nothing to its right blocking it, then go right a little bit. or if there is a car in front and nothing to the left but somthing to the right then turn left and speed up(to make a pass).

just think through what a real-world person would need to know in order to avoid other cars and pass them.
1.where is the other car
2.where is an opening around that car
3.execute the pass or turn to avoid

I may post a simple racing AI Thought proses later

If you go that route, here are some pointers (and mistakes I made, this is in the context of a Wipeout style AI).

Rotation might cause problems: in 2.56a I used a small torque force to turn the AI, this causes the AI to spin wildly when it hits unusual angles in the track mesh. If you use pure Drot this works really well, but it looks strange as turns of +/- 5 look juddery as they turn. This was using dynamic / rigid body physics.

With sensor ‘whiskers’, certain track shapes like U turns and narrow turns cause problems as the further ahead you look, the AI will turn into the bend too early.If the look ahead is too short, you will need a greater force to turn, which can again cause problems.

In addition, when a whisker is triggered, ensure the others are disabled momentarily (like through states) as otherwise the opposite sensor will eventually brush the track and the AI will get confused.

I did try helper nodes that instruct the AI to do things like brake or acellerate when collided with.

Sensor style AI will never have a good racing line, whilst waypoint AI will, although the latter will be less random during a race. I did try to mix both, but I realised that when the AI switched from ‘seek’ mode (in that the AI follows waypoints) to ‘evasive’ (using rays/radar) the AI would miss nodes. When the AI switched back to ‘seek’, it would have passed several nodes and would track back to them (going the wrong way round the track).

I hope this helps a little, and avoids the frustration I went through.

i would suggest using a node based path for the ai to get around the track, but then use sensors for the “local AI” this would mean that with no interference the AI could run smoothly around the track, but if there was an object that got in its way, it could find its way around. i may explore this concept a little more.

Hhhe! Beatt you tto it, kendrick1397, look down that linked thread,you will see me ask if this can be modified, with a kind response that shows the script in a race context.