Flee Behavior

The Flee Steering Behavior has the opposite behavior as the Seek Steering Behavior. That is, instead of approaching the Target Position, it moves away from the Target Position.


The code snippet below shows how to compute the Flee Steering velocity.

Line 1 shows the creation of the Flee instance object. The Flee behavior requires a target position. This position is provided in line 2. Assuming you have created an instance of your character, you can then compute the Final Velocity as shown in line 3.

//1. Create a Flee Steering Behavior
U4DEngine::U4DFlee *fleeBehavior=new U4DEngine::U4DFlee();

//2. Set the Target Position to flee from
U4DEngine::U4DVector3n targetPosition=U4DEngine::U4DVector3n(2.0,0.0,3.0);

//3. Compute the final "flee" velocity for the character. uSoldier is an instance of your game character.
U4DEngine::U4DVector3n finalVelocity=fleeBehavior->getSteering(uSoldier, targetPosition);

//Set the final velocity y-component to zero.

//Check if the resulting velocity is set to zero. Do this as a a safeguard. I have to fix this issue.
    uSoldier->applyVelocity(finalVelocity, dt);