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);
}It's simple!
t is <= 0, Lerp will return a.t is >= 1, Lerp will return b.t is in between 0 and 1, Lerp returns a value between a and b."Give me an example..."
value = Mathf.Lerp(50, 100, t);
t = 0.0f, value is 50.t = 1.0f, value is 100.t = 0.2f, value is 60.t = 0.5f, value is 75.t = 0.8f, value is 90.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.
Drag the slider to modify t, edit a and b in the code below.
value = Mathf.Lerp(, , 0.5f);
// value: 75