Seek Behavior

The Seek steering behavior returns a Final Velocity that directs an agent towards a target position. The AI system takes into account the Current Velocity of the agent when computing the final velocity.


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

To use the Seek Behavior you must create an instance of the behavior as shown in line 1. Next, you must specify a target position for the agent to approach as shown in line 2. Assuming that you have created an instance of your character, you can then compute the Final Velocity as shown in line 3.

The getSteering() method takes as a parameter the instance of the character and a target position.

//1. Create Seek Behavior
U4DEngine::U4DSeek *seekBehavior=new U4DEngine::U4DSeek();

//2. Set target position to seek
U4DEngine::U4DVector3n targetPosition=U4DEngine::U4DVector3n(2.0,0.0,3.0);

//3. Compute the final "seek" velocity for the character. uSoldier is an instance of your game character.
U4DEngine::U4DVector3n finalVelocity=seekBehavior->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);

The clip below shows the behavior of the Red agent approaching the Astronaut agent using the Seek Steering behavior.