Tutorials » Artificial Intelligence System » How to enable the Wander Steering Behavior

The Wander Steering Behavior creates the illusion that the agent is randomly walking around the game scene.

Image

You can set the distance offset between the agent and the Wander target using the method below: void setWanderOffset(float uWanderOffset)

You can also set the wander circle radius using the method below: void setWanderRadius(float uWanderRadius)

And you can also set the rate at which the agent computes a new random velocity. void setWanderRate(float uWanderRate)

The snippet below shows how to compute the final velocity using the Wander Steering Behavior.

//1. Create an instance of the Wander Steering Behavior
U4DEngine::U4DWander *wanderBehavior=new U4DEngine::U4DWander();

//2. Set the Wander Offset
wanderBehavior->setWanderOffset(3.0);

//3. Set the Wander Radius
wanderBehavior->setWanderOffset(2.0);

//4. Set the Wander Rate
wanderBehavior->setWanderRate(0.5);

//set wandering position
U4DEngine::U4DVector3n targetPosition;

//5. Compute the final Velocity using the Wander Steering Behavior. uSoldier is an instance of your game character.
U4DEngine::U4DVector3n finalVelocity=wanderBehavior->getSteering(uSoldier, targetPosition);

if(!(finalVelocity==U4DEngine::U4DVector3n(0.0,0.0,0.0))){
    
    uSoldier->applyVelocity(finalVelocity, dt);
    uSoldier->setViewDirection(finalVelocity);
    
}