top of page

How To: Racing Line

Racing lines can be used to improve your AI going around the track, to calculate optimal times for completing a race and for detecting any trouble spots. But what is a racing line and how can we calculate it?

A racing line is the optimal path around a race track. Following this path will improve the speed time it takes for a vehicle to complete the track. Those of us who played Racing Games or have raced vehicles in real life have an intuitive sense of what that is but let's give it a proper definition so we could calculate it.

A racing line is a line going through the track that minimizes curvature while using the full extent of the track. The racing line may change slightly for different vehicles but this definition will do. Following this line helps us go faster because minimizing the curvature of the line the vehicle takes through the track helps the vehicle maintain more of its velocity through out the track.

How do we calculate a racing line in Velocity Rage?

The method we choose to calculate the racing line in our game is through the use of connected spring loaded hinges. These hinges exert a force on both their ends acting to maximize the angle between the two lines and the center. Connecting them together results in movement of the forces around until each connected joints have the maximum angle allowed by its constraints on the track.

Code for stepping a hinge through time for the simulation

there are some limitations of the movement of the hinges in the code

In our case we position hinges facing the direction of the track heading and we limit their movement along the track to move only to the left or right. we also limit each hinges movement to a radius so that the hinge will not move out side of the tracks bounds.

The hinges stepping through time creating the line

In the curves of the track the positioned hinges will have more force acting on them from the start and the straight areas of the track will have hinges at rest. The force gets transferred from the curved areas of the track to less curved areas until the system is at rest.

Now that we have a racing line, we can also calculate a speed line for our vehicles using some of the vehicles parameters such as its turning radius at different speeds. using that we can calculate the speeds the vehicle needs to be at to get through a curve following our racing lines. Going further we can calculate when exactly the vehicle needs to start breaking and what are the estimated times that it should take the vehicle to complete the track.

What do we do with it?

The AI uses this line to be more competitive, it will try to follow this line when ever possible, that is if it is not trying to pass someone, avoid an obstacle or getting bumped into a wall. This can significantly improve the time it takes the AI to complete the track and makes for a much better experience racing the AI.

Resources:


bottom of page