41.1 Introduction
Typically, track positioning in racing games is done by analyzing the vehicles surround- ing an AI, choosing the best vehicle to overtake, block, avoid, etc., and then moving the vehicle off the racing line to achieve this behavior. This system works well and has been used in many racing games to excellent effect, but it does have one flaw, namely that it is reacting to a single vehicle at a time. In most racing situations, this works fine but it can lead to some unusual behavior when driving in a pack. An example is when a vehicle pulls out to overtake a vehicle directly in front of it and returns to the racing line, only to then need to pull out again to overtake another vehicle that is a bit further down the track. An intelligent driver would overtake both vehicles in a single maneuver. The purpose of the heat vision system is to solve this problem.
41.2 The Heat Vision System
The heat vision system is based upon the heat map idea used in real-time strategy games. It consists of a one-dimensional "heat line" which spans the width of the track at the car's position. "Heat" is then added to (or removed from) the heat line based upon the position of the racing line, the vehicle's current position, other vehicles, etc. Once all the vehicles have written into the heat line, the vehicle is then directed to move from its current position to a position with lower heat. In this way, the vehicle will find the optimal track position based upon its current circumstances in relation to the other vehicles on track. The heat line is stored in a one-dimensional fixed sized array of floats that is scaled to the width of the track at the vehicle's position.
41.3  Writing into the Heat Line
From here on, the target vehicle will refer to the vehicle whose heat line is being written into and the observed vehicles are the other vehicles around the target. Writing into the heat line for each target car is a three-stage process. First, the vehicles are culled to only include the vehicles that the target may be affected by. This would be all the cars within a short distance (e.g., 50 m) of the target, as well as some particular cases (e.g., for gameplay reasons we may always care about any cars approaching from behind the target). The second stage is to run a series of simple tests that determine details of the observed vehicles. These simple tests will include whether the observed vehicle is on the track, alongside the target, in a good position to block/draft (i.e., not too far away and traveling at a minimum speed), should be overtaken (target is approaching quickly), etc. Note that multiple tests may be true for a given observed vehicle (e.g., a vehicle might be good to draft and also good to overtake). The final stage is to write into the heat line based upon the results of these tests. This is done by running a number of passes, each writing a different heat signature (shape) into the heat line. It is also important that heat from the ideal racing line is written in at this stage as well. Some examples of these passes include the following: • Position: It is not possible to drive in the same place as an observed vehicle, so write a large amount of heat at this position. • Block: If the observed vehicle is behind the player, it may make a good target to block so remove heat at this position. • Draft: If the observed vehicle is in a good position for drafting, remove heat based upon a drafting cone produced by this vehicle. Although it is possible to combine the test and write stages into a single stage, keeping them separate has the advantage that they can be used by other systems as well. Furthermore, it is likely that the heat vision system will not be used at all times, so these simple tests can still be used with the more traditional behavior methods. To illustrate this, if the vehicle is off track or facing the wrong way after spinning, it does not make sense to use the heat vision system, but the tests "on track" and "is spun" are still required to aid in the vehicle's recovery to track. An example heat signature used for drafting and for the vehicle's position. The amount of heat that gets added in or removed is determined by a number of factors. Figure 41.1 shows the heat signatures that a number of different behaviors may add in.
41.4  Smoothing the Output
Once all the observed vehicles have been processed, the resultant heat line may be quite rough with many discontinuities. Since the heat line is a simple array of floating-point values, graphical techniques can be used to smooth it. Smoothing the line is important as it will remove any small discontinuities that may cause "snagging" when determining the desired track position.
41.5 Determining the Desired Track Position
Once the heat line has been created and smoothed, it becomes necessary to determine the desired track position. This is ideally the point on the heat line with the minimal amount of heat. However, it may not be possible to actually move to this point, as there may be a large "heat hill" in the way. This "heat hill" could be caused by a vehicle traveling along- side the target where the large heat acts as a solid boundary to lateral movement. Similarly, the lowest point may be beyond a smaller hill, which would represent a crease between tactical minima that we would want to move past. See Figure 41.2. In practice, in order to find the ideal track position, the target position should be moved from the vehicle's position along the line with decreasing heat. In order to avoid local minima (i.e., where a small heat hill exists) momentum and friction should be applied to the target point's movement. This is analogous to rolling a ball down the hill, in that the ball will roll downwards and will have enough momentum to overcome any small bumps. Where the ball settles is the target vehicle's ideal track offset position. Once the ideal track
Figure 41.2
The heat line (at the bottom) for the circled car. The heat added is proportional to the distance along the track from the car. Note how the area with lowest heat is closest to the vehicle that the car is alongside. position has been found, this can be converted into a track offset that can then be passed to the steering controllers.
41.6 Implementation Notes
From the description of how the heat is written, it may appear that it is not necessary to actually retain information of whether an observed vehicle is alongside, good for drafting, etc., since we will write the heat signature for all these tests into the heat line irrespective of what the final behavior is. However, steering is only part of a behavior; it may also be necessary to modify our speed. A simple example of this would be if the game mode requires the AI to follow another vehicle, such as when doing a parade lap during a Formula 1 race. In this case a modified drafting behavior would be used to add in the heat, but we'd also need to match speed with the vehicle we are drafting/following. Since there are many times when we may need to know which specific observed vehicles are affecting our position, it is useful to maintain an array which maps a point on the heat line to the observed vehicle that has provided the most heat. In this way it is straightforward to quickly identify which vehicle has the most influence on the target vehicle at any one time. Maintaining this list also aids immensely in debugging. The actual size of the different heat signatures that the vehicles can add is determined by a number of factors that can include relative speed, driver characteristics, and difficulty. As an example, for a vehicle in front, an aggressive driver will add heat with a smaller lateral spread than a less aggressive driver. This will result in the aggressive driver requiring less space to overtake and so he will overtake while leaving a smaller separation between the vehicle, as compared with a less aggressive driver. For these reasons, as well as game balancing, it is useful to be able to scale the heat signatures in multiple dimensions. For a square-based heat signature, the width across and the distance along the track should be independently scalable, whereas for a drafting cone the length, angle, and fall off should be controllable. By linking these scalable values to a driver characteristic, it becomes possible to give personality to the different drivers. For example, you could have one driver that rarely drafts (short length and small angle) and overtakes giving plenty of space (large width applied to observed vehicle's position heat signature).
41.7 Conclusion
This article has introduced a novel method for determining the optimal track position for a vehicle. Instead of choosing a single vehicle to react to and defining the behavior based upon that vehicle's position (i.e., best target vehicle should be drafted to activate the draft behavior), the heat vision system accounts for all the surrounding vehicles to build up a localized tactical view of the track. Because of this, the vehicle doesn't need different driving behaviors such as alongside, block, or overtake, but instead these actions occur naturally. This system works well when driving on the track, especially when in a pack, but doesn't work in other situations such as recovering back to the track. It is also only suitable for track-style racing games where there is a defined track, so is not suitable for free roaming games like arena-based destruction derby games.