I'm reading Programming Game AI by Example, by Mat Buckland. What I don't understand there is why the individual behaviors return a vector representing change in velocity, but the combined result is treated as a force vector.
Here's the excerpt from the update function:
Vector2D SteeringForce = m_pSteering->Calculate();
//Acceleration = Force/Mass
Vector2D acceleration = SteeringForce / m_dMass;
//update velocity
m_vVelocity += acceleration * time_elapsed;
//make sure vehicle does not exceed maximum velocity
m_vVelocity.Truncate(m_dMaxSpeed);
//update the position
m_vPos += m_vVelocity * time_elapsed;
And m_pSteering->Calculate()
returns the weighted sum of different steering "forces", like Seek
Vector2D SteeringBehavior::Seek(Vector2D TargetPos)
{
Vector2D DesiredVelocity = Vec2DNormalize(TargetPos - m_pVehicle->Pos())
* m_pVehicle->MaxSpeed();
return (DesiredVelocity - m_pVehicle->Velocity());
}
So, how come steering functions like Seek
just return change in velocity and don't take mass into account, but still get used as force?
Here's the source code