Lerp Visualizer
Find the sweet spot between A and B.
How does it work? ↓How does Lerp work?
The Basic Formula
Lerp stands for Linear Interpolation. It takes three arguments:
a start value (`A`), an end value (`B`), and a weight (`t` or
`alpha`).
Result = A + (B - A) * t
If `t = 0`, the result is exactly `A`. If `t = 1`, the result is
exactly `B`. If `t = 0.5`, the result is directly in the middle.
The Smoothing Trick (Asymptotic Averaging)
Often, game developers use Lerp *incorrectly* for smoothing
cameras or chasing objects by doing something like:
current = lerp(current, target, 0.1)
While this creates a nice "ease-out" effect, it is fully dependent
on your framerate. A player running at 144Hz will have a much faster
camera than a player at 60Hz.
To fix this, you use **Frame-Rate Independent Lerp** using delta
time (`dt`) and a decay rate:
current = lerp(current, target, 1.0 - Math.exp(-decay *
dt))
Extrapolation (t > 1 or t < 0)
What happens if `t` goes beyond 0 or 1? Depending on the engine, `Lerp` might be clamped (meaning it stops hard at A or B). If the engine provides an `LerpUnclamped` function, pushing `t = 1.5` will actually push the result 50% *past* point B in the same direction!