# Ai for racing type game

This topic is 4932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am making a simple boat racing game where you race around a loop against other racers. I have the player going around but now I have to start working with the racers. I am trying to figure the best way to get a boat around the loop. The three I have are: Pathfinding: Use something like A-star to search to the next checkpoint/waypoint Rule Base System: Drive straight and check if we are going to crash and avoid it WayPoint: Go to the next waypoint and then continue to the next although I think this would look unrealistic and they would all be going the same way. Does anyone else have any suggestions on how to implement some sort of driving AI or any good articles I could read on driving AI because the only one I found Used the last option which I don't think would work too great. Thanks for any help or suggestions, vbuser

##### Share on other sites
The waypoint system doesn't have to be linear, you could just use it as a guideline to tell the AI the general direction it has to go in. The actual movement could be as erratic as you want it (by adding degree of randomness and error). It could be programmed to accept that it's touched a waypoint when it goes within a certain radius (this lets it do wide curves and such, without it trying to get to the exact point the waypoint is at)

(excuse the crappiness of my diagram...)

Red = waypoint
Pink = Area around each waypoint (error margin)
Cyan = AI path taken

Not sure how feasible this is but maybe you could use each waypoint along with an interpolation function to calculate a more curved path.

##### Share on other sites
Thanks for the reply. I think I am going to use a combimation of a rule-base system and the way-point system. The rule system will be for avoiding other racers and I think I will have the checkpoints all the way across since I already have them there for the players. I think the only problem I will have will to get it to go in somewhat reasonable path. Again thanks for the reply.
cya,
vbuser

##### Share on other sites
im about to do a racing game and had the same question, but seems like I found my answer without asking, but what is the interpolation function?

##### Share on other sites
That was a stupid idea actually. You're probably best calculating the angle between the waypoint and the car (atan2(car_y-wp_y, car_x-wp_x)) then just rotating the car gradually until it reaches that angle. That should simulate turning around corners

##### Share on other sites
If you are still looking I found this tutorial on a other forum and it seemed to help except I don't have gradual turning yet. Steering Behaviors For Autonomous Characters
Well good luck on your game.
Cya

##### Share on other sites
I've only made one racing game (Hurryhover). However, I did make it in one weekend and it had AI which was fairly difficult to beat and didn't cheat.

The checkpoints for human players (and for scoring purposes) don't need to be the same as waypoints for the AI.

In fact, it probably won't work if they are.

I found that I had far more AI waypoints than checkpoints. Checkpoints were used by the game manager to determine who was winning (basically, to tell when you'd done a lap). AI waypoints were used by the AI (which was totally separate) to work out where it needed to go.

I used a sort of lookahead system, where I not only looked at the next waypoint, but also the one after, and worked out the angle between them.

This meant that on sharp corners, the AI could realise that it needed to slow down and do so as necessary.

I was going to implement different "personalities" for the different opponents, just by tuning the same AI algorithm slightly differently (one would be cautious, another reckless).

Bear in mind that you don't always need to wait until you reach a waypoint before moving to the next - you could look ahead a certain distance, which could make the AI better. It just needs lots of tuning.

AI on lots of racing games cheats. This is of course, a cop-out. But mine didn't :)

Mark

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015755
×