How to stop transform movement at a certain point?

I have this, but is continues forever.

if(condition == true){
transform.localPosition = Vector3.Lerp(transform.localPosition, transform.localPosition + offsetPosition, moveSpeed* Time.time);

You keep using the “transform.localPosition” in your function, but every time that function gets called, the value of “transform.localPosition” is different because you modified it in the previous call.

There is never a stopping point because your stopping point is “transform.localPosition + offsetPosition”, which is always changing. Exactly like a carrot dangling in front of a donkey. The donkey will never get to the carrot because it is always his position + an offset, so no matter where he goes, he will never get to it:

alt text

You need to save the start and stop position some place else, that way they will never change when “transform.localPosition” changes. Try doing something like this:

if(condition == true)
    transform.localPosition = Vector3.Lerp(start, stop, moveSpeed* Time.time);
    start = transform.localPosition;
    stop = transform.localPosition + offsetPosition;