Finding a balance between physics simulation and AI control is always difficult. Learn how it’s done in realistic racing games with racing cars and bikes alike.
Paulo Maninetti (Senior Programmer at Milestone, previously Game Programmer at Ubisoft)
I’m not really too interested in racing games, so this, while competent, didn’t appeal – my notes are definitely incomplete. Still, some good notes regarding what to do with physics and AI in some cases.
Racing AI Tutorial
AI has a physics interface where it inputs the throttle, break and turning to get their position out of the interface. This is a black box because it would take too much complexity to forecast exactly the results of an action.
Altering the behaviour on the track, there is the racing line – the best possible line around the track. We start with a generated line just done with an algorithm. You can also get an edited line which is more central to the track. These two can then be merged or changed. To represent them you would cut up the line into straight segments and fixed radius curves. After this the representation can be made into smoother splines.
To simplify it might be points on the track instead of full lines, such as a point every 2 meters.
Since the racing needs anticipation you can aim for a further target to do steering; steer = angle * factor basically, or advanced might be steer = lean which resulting radius leads ot the target (given current speed).
For speed – throttle and breaking – it depends what AI you want. You can simply max throttle if not at full speed and can go faster, and max break if needing to be slower. Can make it smoother/more aggressive as needed for personality too.
Recovery mechanics also can be implemented such as the AI detecting to much drifting so uses counter steer (in a car), and in a bike would use the rear break if detecting a problem with the angle of the bike to align it again. However; don’t do it too much because of loss of performance.
Avoiding colliding perhaps means adding a collision sphere but this is too simple and can lead to errors or late reactions. Comparing relative speeds is a better idea, if we’re going to impact – slow down!
Overtaking needs to also check speed, but also needs a target to overtake which is inside or outside of a car or bike to overtake.
As for mistakes, some are “natural” errors overtaking or colliding, but there are some generated ones possible with the steering, throttle and break usage, and falling off bikes.
Optimising AI Performance
Fairness plays a part – simplifying the physics for the AIs means it gets good performance and easier for group situations but not too realistic and difficult to maintain a fair situation with the player. Doing (almost) the same player physics is ardour – difficult to get performance but looks better and is fairer.
The AI doesn’t need to have a perfect grasp of physics but estimations work, and information on the track where it says what the speeds should be at each point would also help.
Iterative design helps greatly – dividing up the track into sections to set acceleration and deceleration areas and grip modifier. Turn off the graphics and let the AI run quickly to get many laps.