# Lerp Explained: What a Lerp Call Computes, and the Two Jobs It Does

How one interpolation function handles both a fixed start-to-end path and a frame-by-frame chase toward a moving target, and why a constant weight makes the second one frame-rate dependent.

> interpolation · lerp · delta time · About 7 min · Nov 2

## Key points

1. `lerp(a, b, t)` computes $a + (b - a) \times t$: a point a fraction `t` of the way from `a` to `b`, with no memory and no notion of time.
2. The same function serves two jobs, and which one it is doing is decided by `a`: a fixed endpoint means a timed path, the object's own current value means smoothing toward a target.
3. Fixed-path lerp drives `t` from elapsed time over a duration, giving constant speed and a definite finish, and it needs clamping, a stop check or a ping-pong or it will overshoot or run on.
4. Follow smoothing feeds each call's output back in as the next call's `a`, so the gap shrinks geometrically: quick at first, gentle near the end, never exactly zero without a snap threshold.
5. A constant weight such as 0.1 is a fraction per call, not per second, so faster hardware closes the gap faster; the weight $1 - e^{-k\cdot\text{delta}}$ makes the same elapsed time produce the same decay at any frame rate.
6. Some engines clamp `t` and some don't — Unity's `Mathf.Lerp` and `Vector3.Lerp` clamp and offer `LerpUnclamped`, while Godot's `lerp()` extrapolates past the endpoints unless you clamp the weight yourself.

---

A line like `position = lerp(position, target, 0.1)` shows up in almost every game project, and it is usually copied before it is understood. The surprise is that the same three-argument function is used for two jobs that behave nothing alike: gliding along a fixed path from A to B, and easing toward something that keeps moving. Mixing them up produces characters that never quite arrive, cameras that feel different on every machine, and tweens that stop halfway.

The function itself is trivial. Almost all the difficulty lives in where its arguments come from.

## What a lerp call actually computes

`lerp(a, b, t)` returns a point the fraction `t` of the way from `a` to `b`:

$$a + (b - a) \times t$$

Three anchor values are worth memorising: `t` = 0 returns `a`, `t` = 1 returns `b`, and `t` = 0.5 returns the exact midpoint. So `lerp(0, 100, 0.25)` is 25, and `lerp(10, 20, 0.5)` is 15.

It works on vectors too, one component at a time. Interpolating from `(0, 0)` to `(10, 4)` at `t = 0.5` gives `(5, 2)`. Positions, colours, volumes, zoom levels — anything with numbers in it can be lerped.

Beyond the formula, three properties explain nearly every bug you will meet:

**It has no memory.** One call is a snapshot of one position. Nothing moves until the next frame calls it again with something different. The motion lives in the surrounding code, not in the function.

**It measures a fraction of the distance, not a speed.** `t = 0.1` means "a tenth of the way from `a` to `b`". It does not mean "move 10 units", and it does not mean "10% per second".

**Some versions clamp `t`, and some don't.** Unity's `Mathf.Lerp` and `Vector3.Lerp` clamp `t` to the range 0–1, so values past the end just return the endpoint; `LerpUnclamped` exists for when you genuinely want to go beyond [1][2]. Godot's `lerp()` does not clamp: the docs state that values outside 0–1 extrapolate past `b`, and you should clamp the weight yourself if that isn't what you want [3]. This is the practical difference between a lerp that silently stalls at the destination and one that sails past it.

## Why one function can do two jobs

Lerp doesn't know what `a` and `t` mean. It only knows "fraction of the way". That gap is where the two jobs come from, and they differ in one specific place: **what `a` is, and where `t` comes from.**

## Job one: sliding along a fixed path

Here both ends stay put and `t` is driven by elapsed time.

```gdscript
# Slide from x = 0 to x = 100 over 2 seconds
var elapsed := 0.0
var duration := 2.0

func _process(delta):
    elapsed += delta
    var t = clamp(elapsed / duration, 0.0, 1.0)
    position.x = lerp(0.0, 100.0, t)
```

Run the numbers. At 60 frames per second, `delta` is about 0.0167, so `t` advances about 0.0083 per frame and the trip takes around 120 frames, each moving the object about 0.83 units. At 30 frames per second the trip takes 60 frames, each moving it about 1.67 units. Different step sizes, identical endpoints, identical two seconds — because `t` comes from elapsed time rather than from the frame count, which is the same reason movement is multiplied by delta time [delta time](https://eulore.ai/articles/game-loop-57422ff7).

Because `t` climbs evenly, the speed is constant. That is the "linear" in linear interpolation. If you want a slow start and a slow finish, you don't change the lerp; you warp `t` before passing it in — it stays between 0 and 1, only its shape changes.

This job has a hard finish line at `t = 1`. Something must stop it: either the `clamp` above, or a check that ends the tween, or a ping-pong that reverses `t` so the motion loops. Fades, UI bars filling, doors opening, a camera flying between fixed points, a platform shuttling between two waypoints — all of them are this job.

## Job two: easing toward a moving target

```gdscript
# Camera that lags behind the player
camera.position = camera.position.lerp(player.position, 0.1)
```

Same function. Completely different job.

Here `a` is the camera's own position from the previous frame — this call's output becomes next frame's input. `b` is a target that keeps moving. And `t` is a fixed 0.1.

Each call closes 10% of the remaining gap, so the gap shrinks geometrically. Start 100 units away and after 10 frames about 35% of the gap is left; after 60 frames about 0.2% is left. The result is a motion that starts briskly and settles gently — which is exactly why it looks good on a camera, a health bar, or an ally trailing behind the player.

Two properties of this job are easy to miss.

**It never actually arrives.** The gap keeps being multiplied by 0.9 forever, getting smaller but never reaching zero. So real code needs a snap threshold: once the object is within a small distance of the target, set it equal to the target and stop.

**A fixed weight is per call, not per second.** With a weight of 0.1, one second of smoothing is 0.9 multiplied by itself however many times the frame rate allows. At 120 FPS that is $0.9^{120}$, essentially zero — the camera snaps instantly. At 30 FPS it is $0.9^{30}$, about 4% of the gap still open — visibly laggy. Same code, different feel on different machines.

The standard fix replaces the constant weight with one computed from `delta`:

$$\text{weight} = 1 - e^{-k \cdot \text{delta}}$$

Why it works: smoothing over a full second multiplies the gap by $e^{-k}$ no matter how that second is sliced. Split it into $n$ frames and you multiply by $e^{-k \cdot \text{delta}}$ exactly $n$ times, which equals $e^{-k \cdot \text{delta} \cdot n} = e^{-k \cdot T}$. Frame rate cancels out, while `k` still controls how quickly the object catches up. This is the formula the Godot docs recommend, in the same note warning that the shortcut weight `k * delta` is still frame-rate dependent, because the weight is a fraction of the remaining gap rather than an absolute amount [4]. That shortcut also misbehaves outright once `k * delta` climbs past 1, since a weight above 1 overshoots the target or gets clamped into an instant snap.

## Telling the two apart in code

The reliable test is not what `t` looks like — it's **`a`**. If `a` is the value you are assigning to, the call is smoothing (job two), no matter how `t` was computed. If `a` and `b` are both fixed endpoints, it's a path (job one).

| | Fixed path | Chasing a target |
|---|---|---|
| `a` | a fixed start point | the object's own current value, rewritten every frame |
| `b` | a fixed end point | something that moves |
| `t` | elapsed ÷ duration, running 0 to 1 once | a small constant fraction, or $1 - e^{-k\cdot\text{delta}}$ |
| Feel | constant speed | fast at first, slowing as it closes in |
| Ending | exactly at `t = 1` | never exact; needs a snap threshold |
| Frame rate | same wall-clock duration regardless of frame rate | depends on how many calls, unless the weight uses the exponential form |

The case that catches people is a call that looks like one job and is actually the other:

```gdscript
position = lerp(position, target, elapsed / duration)   # looks like a timed move
```

That reads like "move there in one second", but `a` is the object itself, so it's job two wearing job one's clothes. Since `t` starts near zero and climbs, the gap gets multiplied by something close to 1 at first and then by something tiny — the object accelerates into the target and, if `t` passes 1 in an unclamped implementation, shoots past it. If you wanted a timed move, freeze the start point once and lerp between two fixed positions.

A four-question checklist for any lerp line you didn't write:

1. Is `a` the object's own current value? Then it's smoothing.
2. Is `t` a constant, or nearly constant? Then it's smoothing.
3. Is `t` derived from elapsed time or a duration? Then it's a fixed path.
4. Does anything clamp `t`, stop the call, or snap on arrival? If not, job one will overshoot and job two will crawl forever.

The short version: `lerp` computes a fraction of a gap, and whether that gap is a fixed route or a shrinking chase is decided entirely by what you hand it as `a` and where you get `t` from. Read those two arguments and the rest of the line follows.

## Mind map

```mermaid
flowchart LR
  L["lerp(a, b, t)"] --> F["a + (b - a) x t"]
  F --> P1["t = 0 gives a"]
  F --> P2["t = 0.5 gives midpoint"]
  F --> P3["t = 1 gives b"]
  L --> Q{"What is a?"}
  Q -->|"fixed start point"| J1["Job 1: fixed path"]
  Q -->|"the object itself"| J2["Job 2: chasing a target"]
  J1 --> T1["t = elapsed / duration"]
  T1 --> S1["constant speed, defined finish"]
  S1 --> N1["needs clamp, stop or ping-pong"]
  J2 --> T2["t = small constant, or 1 - exp(-k x delta)"]
  T2 --> S2["gap shrinks geometrically, slows near target"]
  S2 --> N2["needs a snap threshold"]
  T2 --> FR["constant t is per call, so feel changes with frame rate"]
  FR --> FX["1 - exp(-k x delta) fixes it"]
```

## Glossary

- Lerp (linear interpolation)：a function that returns a point a given fraction of the way between two values, computed as `a` plus the gap times that fraction.
- Interpolation weight (`t`)：the 0-to-1 number telling lerp how far along the gap to land; it is a fraction of the distance, not an amount or a speed.
- Extrapolation：what happens when the weight goes below 0 or above 1 — the result continues past the endpoints instead of stopping at them.
- Fixed-path lerp：both endpoints stay put and the weight is driven by elapsed time over a duration, giving constant speed and a defined finish.
- Follow smoothing：calling lerp every frame from an object's own current value toward a moving target, using the previous result as the new start, so the gap shrinks geometrically.
- Frame-rate-dependent smoothing：smoothing whose result depends on how many updates happened rather than only on elapsed time, so the feel changes with hardware speed.
- Snap threshold：a small distance at which smoothing stops and the value is set equal to the target, since a shrinking gap never reaches zero on its own.

## Sources

1. [Unity Scripting API: Mathf.Lerp — states that the interpolation value t is clamped to the range [0, 1].](https://docs.unity3d.com/ScriptReference/Mathf.Lerp.html)
2. [Unity Scripting API: Vector3.LerpUnclamped — the variant that allows t outside 0–1 and extrapolates past the endpoints.](https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Vector3.LerpUnclamped.html)
3. [Godot @GlobalScope class reference: lerp() — out-of-range weights are allowed and extrapolate, so the caller must clamp.](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html)
4. [Godot interpolation tutorial — smoothing a moving target with lerp(), the framerate-dependence warning, and the 1 - exp(-speed * delta) weight.](https://docs.godotengine.org/en/latest/tutorials/math/interpolation.html)

---

Original article: https://eulore.ai/articles/lerp-e50ac7a2

> **Eulore** · Start small. Go deep.
>
> Eulore is an AI learning tool built around connected articles, each a 5–10 minute read. Ask questions as you go and help shape what comes next. That’s how this article was created.
>
> Start your own series → https://eulore.ai
