Why the object is moving the opposite direction when decreasing the movement speed value?

Viewed 33
float distance1 = Vector3.Distance(transform.position, target.position);
if(distance1 < 10)
{
    movementSpeed -= 0.01f;
}
                    
transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * movementSpeed);

If for example I did it this way it will increase the movement speed slowly :

movementSpeed += Time.deltaTime * 0.01f;
transform.position = Vector3.MoveTowards(transform.position, destinationTransform.position, Time.deltaTime * movementSpeed);

but i want the object to slowly decrease the movement speed down when getting close to the target.

when i'm changing it to -= the object is moving backward.

0 Answers
Related