To implement the seek behavior for our player, we will need a derive force that will redirect the agent toward a target position. In the seek behavior, our character will overshoot the target because the force applied on the player will be more, which will make the player overshoot the target and then return to the target. It will take a finite amount of time before coming to rest.
Seek behavior is something similar to the following screenshot:
The preceding image explains the algorithm that will be used to implement the seek behavior. In our case, we will need to seek to the target and have to follow the following algorithm:
Vector desiredVelocity = targetVector – player.locationVector;
desiredVelocity.normalize;
desiredVelocity *= player.maxSpeed;
return (desiredVelocity – agent.locationVector);