06 / Camera
Camera smoothing & look-ahead
follow softly, aim ahead
A camera glued to the player passes every stop and dash on to the whole screen. Smoothing lets it close only part of the gap each frame, so it trails slightly and settles. Look-ahead aims a little in front of where the player is heading, so more of what's coming is in view. The ring on the floor marks the camera's aim; turn and dash to see it trail behind and lead ahead.
- Third-person and top-down follow cameras
- Side-scrollers
Prompts to paste
Smooth the follow camera and add look-ahead: aim at the player position plus velocity × 0.3 s (that offset itself smoothed over 0.3 s), and each frame move the aim point toward it by 1 − exp(−dt / 0.2) of the gap rather than snapping to the player.
Rework the follow camera with damping and look-ahead. Each frame, compute a look-ahead offset of velocity × 0.3 s and smooth it with damping over 0.3 s so it doesn't flip the instant the player turns around. The goal is the player's position plus that offset. Move the camera's aim toward the goal by (goal − aim) × (1 − exp(−dt / smoothTime)), with smoothTime around 0.2 s, and keep the camera's offset from its aim fixed. Snap straight to the player on respawn or teleport, and make smoothTime and the look-ahead time tunable.
Examples
Side-scrollers
Lead horizontally and smooth vertical movement more heavily, so small hops don't bounce the whole screen.
Twin-stick and top-down
Lead toward the aim direction or the cursor rather than the movement, so players see what they're shooting at.
Know when to cut
On respawn, teleport or a scene cut, place the camera directly. Easing across the whole map is disorienting.
Pitfalls
A fixed lerp each frame
lerp(camera, player, 0.1) per frame follows faster at higher frame rates. Use 1 − exp(−dt / smoothTime).
Look-ahead that snaps
Without smoothing the offset, the camera lurches across the screen every time the player turns.
So smooth the player escapes
A long smoothing time at top speed lets the player run off screen. Keep it short, or add a deadzone.
Starting values
| Setting | Value | Note |
|---|---|---|
| Smoothing time | 0.1–0.3 s | |
| Look-ahead | 0.2–0.5 s of velocity | |
| Look-ahead smoothing | 0.3–0.6 s |