Control Loops Outside the Lab · 04
Choosing the Damping of a Spring
A following camera needs to catch up and stop cleanly. Spring speed and damping make those two requirements easier to tune.
In a game, a player stops at the edge of a platform, but the camera keeps moving. It passes the desired framing, corrects back, and wobbles before settling. Turning down the follow speed removes some of the wobble, at the cost of making every movement feel late.
This is a tuning problem with two different requirements: catch up promptly, and arrive without an objectionable bounce. One “smoothness” slider often makes it hard to tell which one is being changed.
A damped spring separates them. It keeps position and velocity, accelerates toward the target, and resists motion in proportion to velocity. The same small model is useful for animated panels, moving indicators, and other interfaces where a destination can change before the previous transition finishes.
A reporting interface can need the same behavior when panning a chart to a selected time interval. A second selection may arrive before the first movement finishes. Restarting a fixed-duration transition from rest can introduce an abrupt change in speed; keeping position and velocity lets the movement continue while its destination changes.
That is useful for the position of a viewport or selection marker. A numeric readout should still show the actual measurement: letting it bounce past the reported value would imply data that never existed. The animation needs a defined role before its response can be tuned.
Give the motion somewhere to go, and a way to stop
Setting a camera’s position directly transmits every target movement. Moving a fixed fraction of the remaining distance each frame softens the result, but introduces lag and depends on frame rate unless the fraction accounts for elapsed time.
A spring adds momentum. That makes interruptions easier to handle naturally: when the target changes, the follower already has a position and velocity to continue from. It also creates the possibility of overshoot.
For a unit-mass follower, the equation is:
acceleration = omega² * (target - position)
- 2 * zeta * omega * velocity
The first term pulls toward the target. The second resists the current motion. omega is the undamped natural angular frequency, in radians per second; increasing it makes the response faster. zeta is the dimensionless damping ratio, which controls the shape of the approach.
For a fixed target and an initial state at rest, a ratio below one produces oscillation. At one, the response is critically damped. Above one, it approaches without oscillating, but more slowly than the critical case at the same natural frequency.
Compare three ways to follow the same movement
Imagine the three dots below as candidate camera positions following one player. Each receives the same target changes. The outer followers keep damping ratios of 0.3 and 2.2; the middle one uses the slider.
The practical question is whether the follower arrives in a way that suits the task. A camera that crosses its desired framing may reveal too little of the space ahead. A selection highlight may look quite pleasant with a small bounce. Neither decision follows from the word “smooth.”
- Target (drag it)
- Underdamped ζ=0.3
- Yours (slider)
- Overdamped ζ=2.2
Start by watching a complete target change at the default frequency. The underdamped follower gets across quickly but has motion left to lose. The overdamped follower takes longer to approach. The critical setting gives a prompt, monotonic response to a step from rest.
Then drag the target back toward a follower while it is moving. This changes the problem: even a critically damped follower can cross a nearby target if it arrives with enough velocity. The usual promise of “no overshoot” assumes appropriate initial conditions; a moving interface will not always provide them.
Finally, raise Natural frequency without changing damping. The response becomes faster while retaining a similar character. The control is in hertz; the equation converts it to angular frequency with omega = 2 * pi * frequency. Separating those two parameters makes tuning less of a guessing exercise.
Position error cannot tell how fast the camera is moving
As the follower approaches its target, the spring force gets smaller. Its velocity does not disappear with the position error. Without enough resistance, momentum carries it through the target and the spring pulls it back.
Velocity feedback removes energy during that motion, before the position error has to change sign. For a stationary target, this is closely related to the derivative term of a position controller.
For a moving target, there is another choice to make. Resisting the follower’s absolute velocity differs from resisting its velocity relative to the target. A camera following a steadily moving player may benefit from accounting for that player’s velocity, but estimating it from noisy samples or sudden target jumps needs care. The simulation uses absolute follower velocity.
Decide what a bad arrival looks like
Critical damping gives the fastest monotonic approach among the critically damped and overdamped cases for this linear model, at fixed natural frequency and from rest. It is a useful starting point, rather than a complete camera specification.
A slightly underdamped response may enter an acceptable tolerance band sooner if some overshoot is allowed. A camera may also need collision handling, speed limits, or different responses on each axis. A spring alone will happily carry a camera through a wall.
Settling needs a definition too. Here it means remaining within 1.5 position units of the target for 0.4 seconds; the measurement clears if the follower leaves that band again. A tolerance appropriate for a large panel may still leave a small text label visibly moving.
Test the update loop as well as the equation
The simulation updates velocity and then position at a fixed 1/120-second step, independently of rendering. A high-refresh display therefore does not make the spring run faster.
This integration method works for the frequencies exposed by the controls, but it is not unconditionally stable. Increasing stiffness far beyond that range, or passing a long frame stall straight into the physics update, can produce oscillation that comes from the numerical method.
For a linear spring, an analytic update is another option when frame intervals vary widely. For a more general simulation, the integrator and its step-size limits need testing.
A useful final test for a camera or interface is to interrupt it: reverse the target midway, move it nearby while the follower is travelling quickly, and introduce a frame stall. A transition that looks good between two resting positions still has to behave well when the next input arrives early.