[SOLVED] What is the correct way to use Vector.MoveTowards?

I remember reading from a few sources that doing this:

transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);

Was bad because it causes the object to move quickly at first, and then ever so slowly as it tries to reach the final position but never actually reaches it. However, I can’t remember where I read this and what the proposed solution was. Can anyone point me in the right direction?

The flaw you describe - “it causes the object to move quickly at first, and then ever so slowly as it tries to reach the final position but never actually reaches it” - is actually a flaw of using this technique with Vector3.Lerp (though I still use it in some cases because I like the way it feels, e.g. for camera motion). That is actually the proper way to use Vector3.MoveTowards.

2 Likes

I think you’re confusing MoveTowards with Lerp. Using a single time step like that for a Lerp will result in exactly what you’re describing. You’re using MoveTowards 100% correctly.

1 Like

Beatcha to it. :wink:

:frowning:

The gold grey mare, she ain’t what she used to be

Thanks guys. I must have mistaken it with Lerp. That explains why I couldn’t find anything about MoveTowards.