# Why is my Texture becoming slower when it approaches it's destination?

I have a texture drawn on screen. Whenever I click on the viewport it remembers its destination and starts moving towards it, until it is there. This is the code I am using therefore:

``````//Check if destination was reached
if ((currentDestination - position).Length() <= movementSpeed)
{
// Stop moving
position = currentDestination;
playerState = PlayerState.Idle;
reachedDestination = true;
}

// If destination is not reached
if(!reachedDestination)
{
Vector2 direction = (currentDestination - position); // gives the direction needed to travel from position to target
angle = (float)(Math.Atan2(direction.Y, direction.X) + MathHelper.PiOver2);

direction.Normalize(); // we need it as a unit vector

position += direction * movementSpeed;
// The Y coordinate stays the same in this case
position.Y = 455;
}
``````

It does work, but the closer the texture is to the destination, the slower it gets. Why is that?

-
Are you sure the normalize step is working right? Because he symptoms you describe sure sound like the vector isn't normalized (ie. the magnitude is greater when the destination is further away) – jhocking Mar 13 '14 at 16:52
Can we assume that `movementSpeed` isn't changing? If it's being changed elsewhere, becoming smaller, that would cause the speed of the texture to be affected. – Neeko Mar 13 '14 at 16:52
@jhocking Your hunch makes sense, but I'd be very surprised if `Vector2.Normalize` wasn't working (that's an XNA provided method, not user). Regardless, definitely worth debugging and making sure a unit vector is being set. – Neeko Mar 13 '14 at 16:55
movementSpeed is never changed. direction before Normalization is Vector2(330:133) after normalization it is Vector2(0,9275043:0,3738123). – Käsebrot Mar 13 '14 at 17:06
I missed the bit mentioned in awsump's answer, that it's not actually moving toward the destination point. The question is misleading, since you say it's moving toward the destination but, well, no it's not; you should probably change that. – jhocking Mar 13 '14 at 17:16

``````position.Y = 455;
The way you're doing this, the X component of the velocity is getting smaller. `direction` is always changing. Even though the distance is closing on the X axis, it stays the same on the Y-axis. So, when it's normalized, the Y distance is relatively greater, so X will get smaller. Something along the lines of this would work.
``````Vector2 alignedDestination = new Vector2(currentDestination.X, 455); //Added line