Separation creates a force that steers a vehicle away from those in its
neighborhood region. When applied to a number of vehicles, they will
spread out, trying to maximize their distance from every other vehicle. See
Figure 3.16, top.
This is an easy behavior to implement. Prior to calling separation, all the
agents situated within a vehicle’s neighborhood are tagged. Separation
then iterates through the tagged vehicles, examining each one. The vector
to each vehicle under consideration is normalized, divided by the distance
to the neighbor, and added to the steering force.
Vector2D SteeringBehaviors::Separation(const std::vector<Vehicle*>& neighbors)
for (int a=0; a<neighbors.size(); ++a)
//make sure this agent isn't included in the calculations and that
//the agent being examined is close enough.
if((neighbors[a] != m_pVehicle) && neighbors[a]->IsTagged())
Vector2D ToAgent = m_pVehicle->Pos() - neighbors[a]->Pos();
//scale the force inversely proportional to the agent's distance
//from its neighbor.
SteeringForce += Vec2DNormalize(ToAgent)/ToAgent.Length();
How to Create Autonomously Moving Game Agents
Figure 3.16. The separation, alignment, and cohesion group behaviors