🤔

Linear interpolation#

Linear interpolation or "Lerp", is a simple function that returns a straight-line value between two points (a and b) based on a normalised value (t).

public static float Lerp(float a, float b, float t)
{
    return a + (b - a) * Clamp01(t);
}

"Huh?"#

It's simple!

"Give me an example..."

value = Mathf.Lerp(50, 100, t);

Vector2, Vector3, Color, Quaternion...#

All lerp functions are linear, and return the in-between values based on a 0->1 t value.
Their usage is the same, even though the applications are varied.

Interactive diagram#

Drag the slider to modify t, edit a and b in the code below.

value = Mathf.Lerp(, , 0.5f);
// value: 75

Usage#