seen the target within the last n seconds. This gives it a sort of mem
ory and produces reasonable-looking behavior.
2. The same as above, but this time the vehicle only tries to hide if the
vehicle can see the target and the target can see the vehicle.
3. It might be desirable to produce a force that steers a vehicle so that it
always favors hiding positions that are to the side or rear of the pur
suer. This can be achieved easily using your friend the dot product to
bias the distances returned from
4. At the beginning of any of the methods a check can be made to test if
the target is within a “threat distance” before proceeding with any fur
ther calculations. If the target is not a threat, then the method can
return immediately with a zero vector.
Path Following
Path following creates a steering force that moves a vehicle along a series
of waypoints forming a path. Sometimes paths have a start and end point,
and other times they loop back around on themselves forming a never-
ending, closed path. See Figure 3.13.
You’ll find countless uses for using paths in your game. You can use them
to create agents that patrol important areas of a map, to enable units to tra
verse difficult terrain, or to help racing cars navigate around a racetrack.
They are useful in most situations where an agent must visit a series of
The paths the vehicles described in this chapter follow are described by
std::list of Vector2Ds. In addition, the vehicle also needs to know what
the current waypoint is and whether it is a closed path or not to enable it to
take the appropriate action when it reaches the final waypoint. If it is a
closed path, it should head back to the first waypoint in the list and start all
110 | Chapter 3
The Steering Behaviors
Figure 3.13. Different types of paths

Get Programming Game AI by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.