Send a link

Racing Line

The Racing Line component store all the information about the ideal racing line, the limits of the tracks and the grip / deceleration values at different parts of the circuit, so the AI can calculate the optimal speed at each point of the track. The same Racing Line can be used for similar vehicles, but if two vehicles have a very different behaviour, they should use different Racing Line because they will probably have very different grip / deceleration optimal values.


Racing Line Creation

The user can create a new Racing Line or load an existing racing line from the Pro Racing AI menu:

Pro Racing AI menu

  • If the user selects the Create Racing Line option, Pro Racing AI will create an new GameObject with a Racing Line component that contains 3 nodes and one track sector, the simplest racing line that can be generated in Pro Racing AI.
  • If the user selects the Load Racing Line option, Pro Racing AI will show a dialog asking for the file which contains the track information. If the user selects a valid file, a new Racing Line component will be added to the selected GameObject or, in case there isn't any selected GameObject, Pro Racing AI will create a new GameObject with a Racing Line component.

Racing Line Gizmos

Ideal Racing Line

In Pro Racing AI, a racing line is represented by a Catmull-Rom spline with 3 or more nodes. It is possible to add new nodes at the end of the racing line pressing the Append Node button, but it is also possible to insert new nodes before and after an existing node pressing the Insert Before and Insert After buttons. Likewise, it's possible to delete a node pressing the Delete Node button.

The Node Subdivision button doubles the number of nodes of the racing line (so it's possible to add a greater level of detail), while the Node Reduction button divides the number of nodes by two (maintaining the general shape of the racing line).

The Closed Path checkbox can be used to tell Pro Racing AI that the beginning and the end of the racing line should be at the same position. It is easier to edit the racing line as an open path and check the closed path toggle at the end of the process.

Finally, the racing line will be updated automatically whenever a node position is updated (in the Scene View or the Inspector) or a new node is created or deleted.

Track Limits

A common limitation of waypoint-based racing AI is that they have little or no information about the track beyond the ideal racing line. Pro Racing AI try to avoid that common pitfall storing in each node the distance to the left and right borders of the track, so it can take into account these limits and remain inside the track limits even when overtaking other vehicles.

In addition, it's possible to define an outer limit (Left Wall and Right Wall distances) that can represent the walls beyond the limits of the track or a red line that shouldn't be crossed by the AI in any case. In addition, we can tell the AI to respawn in the nearest position of the racing line if it crosses this outer limit. Finally, the banking parameter will allow us to define the inclination in that point of the track.

Track Sectors

Some racing AI packages try to define a max speed value for every node in the racing line (or each point of the track), but this approach has an associated problem: even if the AI do its best to match the target speed, it can be a really challenging task if the it doesn't have any information about the grip in different parts of the track. In Pro Racing AI, instead of defining an arbirary speed value for each node, the max speed is calculated using the following parameters:

  • Turning Radius: whenever a node is updated, Pro Racing AI will recalculate automatically the turning radius for every node in the racing line (a long straight is considered a corner with an infinite turning radius). The max speed at each point of the track is directly proportional to the turning radius at that point of the track.
  • Sector Grip Parameter: this parameter represents the grip of the track and, in combination with the turning radius, it is used to calculate the max speed at the slowest point of the sector: the max speed at the slowest point of the sector is directly proportional to the value of the grip parameter.
  • Sector Deceleration Parameter: this parameter represents how fast can brake the vehicle in this sector. Low deceleration values will make the AI brake too soon, while high values will cause the AI to drive more aggressively and improve their lap times. However, the AI vehicle can spin or go out of the track if it tries to drive too aggressively, so this parameter should be used carefully (and should be tweaked only after finding the ideal value for the grip parameter).
  • Sector Look Ahead Parameter: this parameter doesn't have any effect on the AI speed. Instead, high Look Ahead values will make the AI start turning sooner while low values will make the AI start turning later, which can have a great influence in the cornering speed.

In addition, we can (and should) divide the track into sectors in order to set the best parameters at each point of the track. Ideally, there should be one sector for every straight and corner in the track, but it isn't strictly necessary. However, we can press the Generate Sectors button to get a good starting point. Then it's possible to modify the End of Sector Parameter to select the percentage of the track (0...1) where the sector ends.

It is possible to create a new sector using the Subdivide Sector button or remove an existing sector with the Delete Sector button. In addition, it is possible to double the number of sector pressing the Sector Subdivision button or divide the number of sectors by two clicking the Sector Reduction button.

The best way to find the optimal values for each parameter is by trial-and-error, tweaking the parameters manually and seeing if the car behaviour improves or gets worse, so it's a slow and repetitive process. We are working in a (experimental) machine learning feature that will make easier to find the optimal values, but at its current state it can't be use reliably if the original values are too far away from the optimal values. For this reason, it's recommended to tweak the sector parameters manually before executing the machine learning process.

Using Racing Line

After setting all the racing line parameters, the user can press the Save to file button or select the Save Racing Line menu option to save the racing line information into a text file. Then there will appear a dialog to choose the path of the file where the racing line information will be saved, but the selected path should be accessible from Unity because it will be needed by the AI. Once the racing line information has been saved into a file, the GameObject is no longer necessary, so it can be removed safely from the scene.