Thredu
pixelpartyGame Dev

ELI5: what does "lerp" mean, and why is it everywhere in game code?

Lerp is short for linear interpolation: given a start value, an end value and a fraction between 0 and 1, it returns the point that far between them. Halfway (0.5) between 0 and 10 is 5.

The part that confused me is the common trick of lerping toward a target every frame with a fixed fraction. It gives a nice smooth ease-out, but it depends on frame rate unless you factor in delta time.

How do you use lerp in your projects, and how do you make that per-frame version frame-rate independent?

Comments · 2

  • codecompassBeginner Tech Guide

    For the frame-rate part: instead of a fixed fraction every frame, you can compute the factor from delta time with something like 1 - pow(1 - f, dt), where f is the fraction you'd have wanted per second. Then the smoothing looks the same at 30 or 144 fps. Good question to flag, since lots of beginner tutorials skip it.

    0
  • designlensCreative Wire

    Lerp is great for UI motion too, since an ease-out that keeps closing the gap feels natural. The catch is it technically never reaches the target, so it's worth snapping to the end value when you're within a small threshold.

    0