//for the evader's current position.
Vector2D ToEvader = evader->Pos() - m_pVehicle->Pos();
double RelativeHeading = m_pVehicle->Heading().Dot(evader->Heading());
if ((ToEvader.Dot(m_pVehicle->Heading()) > 0) &&
(RelativeHeading < -0.95)) //acos(0.95)=18 degs
//Not considered ahead so we predict where the evader will be.
//the look-ahead time is proportional to the distance between the evader
//and the pursuer; and is inversely proportional to the sum of the
double LookAheadTime = ToEvader.Length() /
(m_pVehicle->MaxSpeed() + evader->Speed());
//now seek to the predicted future position of the evader
return Seek(evader->Pos() + evader->Velocity() * LookAheadTime);
TIP Some locomotion models may also require that you factor in some time for
turning the agent to face the offset. You can do this fairly simply by increasing
the LookAheadTime by a value proportional to the dot product of the two head-
ings and to the maximum turn rate of the vehicle. Something like:
LookAheadTime += TurnAroundTime(m_pVehicle, evader->Pos());
Where TurnAroundTime is the function:
double TurnaroundTime(const Vehicle* pAgent, Vector2D TargetPos)
//determine the normalized vector to the target
Vector2D toTarget = Vec2DNormalize(TargetPos - pAgent->Pos());
double dot = pAgent->Heading().Dot(toTarget);
//change this value to get the desired behavior. The higher the max turn
//rate of the vehicle, the higher this value should be. If the vehicle is
//heading in the opposite direction to its target position then a value
//of 0.5 means that this function will return a time of 1 second for the
//vehicle to turn around.
const double coefficient = 0.5;
//the dot product gives a value of 1 if the target is directly ahead and -1
//if it is directly behind. Subtracting 1 and multiplying by the negative of
//the coefficient gives a positive value proportional to the rotational
//displacement of the vehicle and target.
return (dot - 1.0) * -coefficient;
The pursuit demo shows a small vehicle being pursued by a larger one.
The crosshair indicates the estimated future position of the evader. (The
evader is utilizing a small amount of wander steering behavior to affect its
motion. I’ll be covering wander in just a moment.)
How to Create Autonomously Moving Game Agents | 95
The Steering Behaviors