Progblog post #15 – Heatmaps and AI vehicle tweaks

Heatmaps and AI vehicle tweaks

I am back again with another post. This time I will talk a bit about how I set up the track with the correct data for the AI vehicle by using heatmaps. I also did allot of tweaking on various systems. Hope you enjoy.


As you may have read in earlier posts, the track that I have created for my graduation race game project consists of sections that have one or more nodes that when connected define a race path. The AI vehicle roughly follows one of these paths and can switch between them based on the current skill level and situation. Each node has a preferred speed for the AI vehicle to reach. The problem was that guessing these preferred speeds is really hard, because of the physics of the vehicle and the track itself. So I decided to make a heatmap. This heatmap is being generated by driving around the track myself and storing my vehicles position and speed at set intervals. After ten or so laps there is enough data to distil a good speed value out of. To visualize all the data I have created an editor that visualizes the locations by putting a label and a colored this at the stored position. The label shows the speed value, this is also shown by the size of the disc and also its color, as seen below.

AI Vehicle - The Heatmap Editor

So from now on I can easily set up the best values for each node in each section interface.

Better Crash Recovery

It sometimes happens that the AI vehicles lose control and go off track. When this happens it’s not really a problem except that they sometimes get stuck in trees or against other vehicles. So to help them get back on track I needed to create some logic that makes them recover. The way I now implemented it is as followed. I check if the vehicle has had a magnitude of the velocity of zero for a small period of time. If so the front sensors are checked and if they are obstructed then the vehicle will go in reverse and steer its max value to the left for a number of seconds. This solution is very simple, but in this case does the trick every time.

AI Vehicle - Crash Recovery

To help the AI to better avoid other vehicles I have updated the sensor system from the trigger based version to a raycast based system.

AI Vehicle - The Sensor System

As you can see these systems still need some tweaking but the basics are at least way better than before.

End Screen/Game

To make the race not go on indefinitely I created logic for checking if the player has gone through all section interfaces. If this is so and the required amount of laps are completed the end game is triggered. When the game ends a screen is shown containing the values as seen below. The data is refreshed with every vehicle that finishes after the player does. This way all data is shown correctly and thus the player can see how he/she has performed.

AI Vehicle - End Screen