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:
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 12. 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.
1# Slide from x = 0 to x = 100 over 2 seconds
2var elapsed := 0.0
3var duration := 2.0
4
5func _process(delta):
6 elapsed += delta
7 var t = clamp(elapsed / duration, 0.0, 1.0)
8 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.
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
1# Camera that lags behind the player
2camera.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 , essentially zero — the camera snaps instantly. At 30 FPS it is , 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:
Why it works: smoothing over a full second multiplies the gap by no matter how that second is sliced. Split it into frames and you multiply by exactly times, which equals . 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 |
| 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:
1position = lerp(position, target, elapsed / duration) # looks like a timed moveThat 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:
- Is
athe object's own current value? Then it's smoothing. - Is
ta constant, or nearly constant? Then it's smoothing. - Is
tderived from elapsed time or a duration? Then it's a fixed path. - 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.