Game Development Reference
In-Depth Information
Getting ready
To implement the flee behavior, we need to flee to the target and follow the following al-
gorithm:
Vector desiredVelocity = player.locationVector -
targetVector;
desiredVelocity.normalize;
desiredVelocity *= player.maxSpeed;
return (desiredVelocity - agent.locationVector);
In the preceding algorithm, we are calculating the force that will be needed to flee the ob-
ject off from the screen. First, we will calculate the direction vector to determine the direc-
tion opposite to the player, so that our object can flee from the target in that location. Now,
in the second step, we normalize the vector and increase its magnitude to its max speed.
Using this algorithm, we will implement the flee behavior for our object.
Search WWH ::




Custom Search