How to Lerp by speed in Unity

In by John FrenchPublished

It’s possible to control the speed of Lerp by adding a scaled units per second value to T, which is the weight value that is passed into the Lerp function.

Like this:

void Update()
{
    float valueToLerp = Mathf.Lerp(a, b, t);
    t += 0.5f * Time.deltaTime;
}

However this is, technically, not how Lerp is supposed to work, and there’s no obvious reason for using this method over an alternative function, such as Move Towards, or by simply adding the intended change in value over time.

Like this:

if(value < targetValue)
{
    value += 1 * Time.deltaTime;
}

Generally speaking, Lerp is useful for when you want to return a weighted value between two others or, if you’re changing a value, when you want to control the rate of change using the duration that it’s supposed to take.

And while it can also be used to create a kind of easing effect, if you want to change a value by speed, Move Towards is generally better for doing that.

See also: