the symptom, in your words

"Camera focus target switch causes jerk — smooth the target, not just the follower"

✓ verified on 26.07.08e
lane Writing gameplayposted

▸ SYMPTOM

A chase camera uses exponential smoothing (Lerp(pos, desired, 1 - e^(-k*dt))) and follows the player smoothly during normal movement. But on a state transition — dismounting, exiting a vehicle, switching from one tracking mode to another — the camera jerks visibly, even though the position lerp is running the whole time.

▸ CAUSE

The position lerp smooths the camera's output, but the input (focus target point and/or follow distance) jumps discontinuously on the state change. A chase camera that tracks an anchor at 1.5x distance while in one state and the body at 1.0x in another switches its desired target in a single tick. The position lerp then chases a target that jumped, and while it smooths the chase, the initial velocity kick reads as a jerk to the player.

Smoothing the follower doesn't help when the thing it's following teleports.

▸ FIX

Give the focus point and follow distance their own exponential smoothing, separate from the position lerp:

snippet
// Per-state raw values
Vector3 rawFocus = isSwinging ? anchor.WorldPosition : body.WorldPosition;
float rawDist = isSwinging ? 1.5f : 1.0f;

// Smooth the target itself (slower rate than position lerp)
float targetRate = 5f;
_smoothFocus = Vector3.Lerp( _smoothFocus, rawFocus, 1f - MathF.Exp( -targetRate * Time.Delta ) );
_smoothDist = MathX.Lerp( _smoothDist, rawDist, 1f - MathF.Exp( -targetRate * Time.Delta ) );

// Position lerp chases the smoothed target (faster rate)
float posRate = 12f;
Vector3 desired = _smoothFocus - cameraDir * _smoothDist;
WorldPosition = Vector3.Lerp( WorldPosition, desired, 1f - MathF.Exp( -posRate * Time.Delta ) );

The target rate (~5) should be slower than the position rate (~12) so the focus point glides across the state switch and the position lerp never chases a discontinuity.

Seed _smoothFocus and _smoothDist to their raw values on the first valid frame, or they'll glide in from the origin on spawn.

▸ WHY IT WORKS

Two nested exponential smoothers at different rates create a cascade: the slow outer smoother eliminates the discontinuity in the input, and the fast inner smoother (position lerp) tracks the now-continuous target without velocity spikes. The state change still happens — the camera still reframes from anchor to body — but it happens over a smooth arc instead of a single-tick snap followed by an asymptotic chase.

Verified on engine 26.07.08e: seen in a real project.
s&box moves fast; an undated fix is a liability. Spot a stale detail?
changelog
  • Published

Want to know when new guides or fixes drop? Join the community to help build this out. Report gotchas, flag outdated fixes, or just lurk.

Join the Discord