How to Pause & Resume a Lerp

Hello,

I have a function where I lerp a sphere up in scale, then I lerp back down in scale. This happens in the update function.

I also have a way to pause the lerp, and then resume lerping. However, once I resume lerping, the scale starts from where it should be if it had not been paused, rather than starting from the paused scale.

Any advice is appreciated. Thanks!

We won’t be able to help you without seeing your code (in code tags, please).

But “pausing and resuming a Lerp” doesn’t make a lot of sense. Lerp isn’t a movement or animation; you put in two things, give it a value from 0-1, and it find a value in between those two things - that’s it. A frequent usage of Lerp includes passing in some sort of time variable, and that makes it a piece of animation. Understanding that there’s no movement inherent in a Lerp is probably vital to fixing your problem.

I suggest you look into a tweening system, such as leantween or dotween. While you could just write the system yourself, I know leantween has a built in pause and it wouldn’t surprise me if dotween did also.

Thanks! I will look into both of those and see if that helps

I tried adding an animation component to the objects that I would like to move. There is an easy Play() and Stop() method I can call, which is great. However, I seem to have the same issue: when I stop an animation, and then replay it, the animation starts over from the beginning, rather than resuming from where the animation left off.

In that case you should be able to use Pause()

It seems there is no pause() ability. However, I’ve found this code:

foreach (AnimationState state in myAnimation)
{
state.speed = 0f;
}

Which did the trick! Strangely, enabling and disabling also had the similar problem of restarting the anim back at its beginning, rather than resuming.

However, setting the state speed worked well. Thanks for the thoughts!