# Translating Steering Behaviour Pursuit sample

I've come across a C++ Sample of from Programming Game AI by Example. For the most part it is fairly understandable, the only thing confusing me is the reference to "m_pVehicle->Heading()" I'm not sure what it means by heading. If anyone could clarify this, I would really appreciate it.

 Vector2D SteeringBehaviors::Pursuit(const Vehicle* evader)
{
//if the evader is ahead and facing the agent then we can just seek

{
}

//and the pursuer; and is inversely proportional to the sum of the
//agents' velocities

//now seek to the predicted future position of the evader
}


On p.87 of the book, you will find the definition of m_vHeading as:

//a normalized vector pointing in the direction the entity is heading.


If you look through the source, you will find:

Vector2D  Heading()const{return m_vHeading;}


Right before your code snippet he explains that if the target being pursued is ahead and almost directly facing the agent, it should just seek directly towards the target's position.

A way to easily determine if the target is ahead, or "in front", of the agent is by using the dot product of the vector from the agent's position to the target's position ToEvader and the agent's heading vector m_pVehicle->Heading(). If the dot product is greater than 0, the target is in front of the agent:

(ToEvader.Dot(m_pVehicle->Heading()) > 0)


You can read more on the dot product and it's uses on pages 23-26.

• Thanks for that, I did read in the first chapter that heading was meant to represent direction, but I thought it was strange that the direction vector wasn't normalized – dbomb101 Aug 12 '11 at 15:04
• @dbomb101 - What makes you think it is not normalized. Actually your code snippet only works if its normalized, otherwise comparing the dot product with -0.95 wouldnt work, so they must be normalized – Maik Semder Aug 12 '11 at 17:29
• Just the fact that some of the other steering behavior methods in the book use a normalized method in them and that one had no mention of it, thus leading me to think something was off about it in the first place. – dbomb101 Aug 13 '11 at 7:07
• dot product ftw. It's often the quick and simple answer to a compex question. – tenpn Aug 13 '11 at 9:11