# Steering Behavior Seeking

I am trying put a seek feature in my code.

Just frame code, not actual code.

 Seek(TargetPos)
{
Vector2D DesiredVelocity = Normalize(TargetPos - currentPos)*MaxSpeed();

return (DesiredVelocity - currentVelocity}


Simply when I press 2, it will change the target, 3 will change the target and so on...

Do I need to make the currentVelocity the old Desired velocity?

Yes, you could make currentVelocity equal to DesiredVelocity.

However, this is going to make your object suddenly change direction in an unrealistic manner. If you want your object to travel more realistically, you should try interpolating from currentVelocity to DesiredVelocity, and set that to currentVelocity.

You do not need to make the currentVelocity equal the old desiredVelocity.

desiredVelocity changes every frame, as the actor changes position in relation to it's target.

Here's an overview of the situation:

You could use the resulting steeringDirection to calculate an incremental change to the current velocity (as per Steering Behaviors For Autonomous Characters):

steeringDirection = seek (targetPos);

// this limits the steering force to a maximum steering force
// to avoid unnatural quick 180 turns
steeringForce = truncate (steeringDirection, MaxForce);

// we calculate an acceleration using the actor's mass
// so bigger things can be slow and have "more inertia"
// while small seekers can be fast and more maneuverable
acceleration = steeringForce / mass;

// and add it to the current velocity, which we then clamp to
// the maximum speed of the actor
currentVelocity = truncate (currentVelocity + acceleration, MaxSpeed);

// and we update the position
position = position + currentVelocity;


Hope I could help shed some light on the situation :)