Skip to main content

Command Palette

Search for a command to run...

Lerp and smoothstep, what they actually do

Published
4 min read
Lerp and smoothstep, what they actually do
T

Just a guy who loves to write code and watch anime.

Intro

You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another.

The problem

You have a value at A. You want it at B. Snapping from A to B looks bad. Animating it manually is annoying.

Lerp and smoothstep do the in-between math for you. That's all they are.

Lerp

Lerp is short for "linear interpolation." Simpler word: "blend." Lerp blends between two values.

lerp(a, b, t) = a + (b - a) * t

Three inputs:

  • a is the start value

  • b is the end value

  • t is how far between them, from 0 to 1

When t = 0, you get a. When t = 1, you get b. When t = 0.5, you get the value halfway. When t = 0.25, you get a quarter of the way from a to b.

That's it. Blend a and b by some amount.

What lerp is used for

Color blending. Lerp red and blue with t = 0.5 to get purple.

Position movement. Lerp position A and position B with t = 0.3 to get a point 30% of the way from A to B.

Volume fade. Lerp current volume toward 0 with t = 0.1 every frame. Audio fades out smoothly.

Camera follow. Each frame, lerp camera position toward player position by t = 0.1. Most game cameras do this.

Brightness change. Lerp current brightness toward target brightness when the player walks into a dark room.

Lerp doesn't care what a and b are. Numbers, colors, positions, vectors. Anything that supports addition and multiplication works.


The catch with lerp

Lerp moves at constant speed. Same speed the whole way through.

Sometimes that's what you want. A simple slide. A simple fade.

Often it looks robotic. Real motion ramps up and slows down. A door opens slowly, swings through the middle, eases into the end. Lerp can't do that on its own.

That's where smoothstep comes in.

Smoothstep

Same idea as lerp (blend between two values), but the curve is soft at both ends instead of straight.

With lerp, you start at full speed and stop at full speed. With smoothstep, you start slow, speed up in the middle, slow down at the end.

smoothstep(t) = t * t * (3 - 2 * t)

You don't need to memorize this. The result is an S-shaped curve. Flat at t = 0 (no movement yet), flat at t = 1 (movement done), steep in the middle (most of the change happens here).


When to use which

Use lerp for:

  • Simple direct blending where the curve doesn't matter

  • Calling every frame with a small t for a smooth follow effect

Use smoothstep for:

  • One-shot animations (door opening, panel sliding in, fade)

  • Anywhere the start and end should feel natural instead of abrupt

  • Animation timelines where t goes from 0 to 1 over a fixed duration

Rule of thumb: lerp every frame for follow behavior, smoothstep over a fixed duration for animation.

The "lerp every frame" trick

The most common use of lerp in games.

camera.position = lerp(camera.position, player.position, 0.1)

This runs every frame. Each frame, the camera moves 10% of the way toward the player.

The result: the camera moves fast when far away, slow when close. It chases the player and decelerates naturally as it catches up. You didn't write any easing logic. The pattern produces it for free.

Use this for cameras, UI smoothing, value tracking. Anywhere one value should chase another.

Bigger t (like 0.3) is snappier. Smaller t (like 0.05) is lazier.