Springs: Bouncy, Critical and Sluggish
A damped spring pulls a value toward its target harder the farther away it is, while drag slows it down. Two knobs describe it completely: says how fast it moves and the damping ratio says how bouncy it is. At exactly it arrives as fast as possible without ever overshooting, which is why interfaces and cameras love it.
What the symbols mean
- Target
Where the spring pulls toward: its resting position.
- Natural frequency
How fast the spring wants to swing, in radians per second. A spring that bounces f times a second has ω = 2πf.
- Damping ratio
The drag you have divided by the drag that would just barely stop the bouncing: below 1 bounces, exactly 1 is critical, above 1 is sluggish.
What the symbols mean
- Offset
How far the value is from its target: u = x − target.
- Starting offset
The offset at t = 0.
- Starting velocity
The velocity at t = 0.
- Damped frequency
How fast the damped spring actually wobbles, a little slower than ω.
What the symbols mean
- Decay rates
Two negative roots. The one closer to zero is the slow one, and it decides how long you wait.
Explanation
A damped spring is simply a rule that pulls a value toward a target, pulling harder the farther away it is, while a drag slows it down so it eventually settles. It's how a menu slides in with a little bounce, how a game camera catches up with the player and how a ponytail keeps swaying after the character stops. The equation looks busy, but it's just two pushes added up: (the spring, pulling back toward the target in proportion to how far off you are) and (the drag, pushing against the velocity). is the acceleration those two pushes produce. The Greek letter (zeta) is called the damping ratio because it really is a ratio: the drag you have divided by the drag you'd need to just barely stop the bouncing. That's the whole model, two knobs and two pushes; bear with it.
Where it comes from. You've met this equation before in Mechanical Vibrations, dressed as a mass on a spring: , where is the distance from the resting position. Measure from the target, , and divide by :
Now give the two coefficients names that mean something to an animator: and . Solving the second for gives , and is exactly the critical damping coefficient from that lesson. So . Game programmers prefer this form because there's no mass and no stiffness to juggle: is "how fast" and is "how bouncy", and you can change one without touching the other.
The three personalities. Try . Every term gets a factor , which is never zero, so what's left is the characteristic equation
Everything hinges on the square root, so everything hinges on whether is below, at or above :
- Underdamped, : the square root is of a negative number, so with . The motion wobbles at inside a shrinking envelope . It overshoots, comes back, overshoots a little less and so on.
- Critically damped, : the square root is , so there's one repeated root and the solution is . No wobble.
- Overdamped, : two negative real roots. The motion is a mix of two decaying exponentials, and the slow one, , takes its time.
The constants come from where the spring starts. For the underdamped case, gives (cosine is and sine is at ), and gives . For the critical case, and gives . Those are the formulas in the box.
Why interfaces and cameras use critical damping. How long you wait is set by the slowest-decaying part of the motion. Its decay rate is when underdamped, when critical and when overdamped. That last one shrinks as grows: at it's only . So the decay rate climbs as you add damping, peaks at exactly when , and falls after that. Critical damping is the fastest you can settle without wobbling. And released from rest, the critical solution is : neither factor is ever zero for , so it never crosses the target. A button that overshoots its spot looks broken; one that crawls looks sluggish. Critical damping is the sweet spot, and there's a race further down where you can watch all three settle side by side.
How far does a bouncy spring overshoot? Released from rest (), differentiate the underdamped solution and the cosine terms cancel, leaving
The first moment it stops and turns around is when again, at . Plug that in: , so . The fraction it swings past is
Notice dropped out: how bouncy it looks depends only on . overshoots by , by about and by . Designers who want "a tiny bit of life" pick around to .
Because the solution is exact, a game doesn't have to simulate the spring at all: it can evaluate the formula at any time. Ryan Juckett's "Damped Springs" article does exactly that, and for a fixed frame time it precomputes the four numbers that carry from one frame to the next. Here's the underdamped case written out:
// Underdamped spring, exact at any time t. u0 = offset from the target, v0 = starting velocity.
const wd = w * Math.sqrt(1 - z * z);
const u = Math.exp(-z * w * t) * (u0 * Math.cos(wd * t) + ((v0 + z * w * u0) / wd) * Math.sin(wd * t));
const x = target + u;
A common mistake. It's tempting to think more damping always means the spring settles faster, because damping is what kills the motion. It doesn't: past the slow root gets slower, and an overdamped spring creeps toward its target. With the same , a spring at takes about times as long as one at to get within of its target.
A common mistake. is in radians per second, not bounces per second. A spring you want to wobble twice a second has , not . And the starting conditions go on the offset: a card at heading for a target at starts at , not .
Springs connect to a lot of this course. The elastic easing curve in The Easing Zoo is an underdamped spring's motion baked into a fixed curve. The frame-rate-independent smoothing of Smoothing That Doesn't Depend on Frame Rate is a spring with the mass taken out, . And because a spring carries its velocity with it, changing the target mid-flight never causes a jolt, which is exactly the problem Chaining and Interrupting Motion works hard to solve for tweens.
See it
Worked examples
A notification card slides to its spot with a spring that has rad/s and . It starts px to the right of its target, at rest. Find its offset from the target, and how far past the target it swings.
- 1
Measure everything from the target: let , the card's offset. It starts at px, and at rest, so .
A camera's height follows its target with a critically damped spring, rad/s. At the camera is m above the target and already moving down at m/s. Find its offset , and check whether it ever dips below the target.
- 1
Offsets from the target: m (above it) and m/s (moving down, toward it).
Practice
Type your answer and check it. Solve them all to complete the lesson.
A slider's knob follows the spring . What is its damping ratio ?
A kg mass hangs on a spring with N/m and a damper with N·s/m, so . Written in the game form , what are (in rad/s) and ? Enter them in that order.
A health bar's displayed value chases the player's true health with a critically damped spring, rad/s. The displayed value is resting at when the player takes a hit and the true health drops to . What does the bar show s later?
A spring with damping ratio is released from rest. By what percent of its starting distance does it overshoot the target?
A door closer's angle (in radians from shut) obeys , starting at and at rest. Find .
A settings panel should slide into place as fast as possible without ever overshooting its spot. It always starts at rest. Which damping ratio should its spring use?
A camera rig uses . What value of makes it critically damped?
A spring with rad/s and is released from rest px from its target. At what time (in seconds) does it reach its farthest point past the target?
The hardest one here. Get it, and you've got this lesson.
A menu designer wants a spring that, released from rest, overshoots its target by exactly and reaches that farthest point s after release. Find the natural frequency in rad/s (to two decimal places).
Where it's used
Spring animations are everywhere in modern interfaces. Mobile UI toolkits describe animations by a damping ratio and a response time instead of a duration, so a card that gets flicked keeps its velocity and settles naturally, and pull-to-refresh and rubber-banding are springs with a moving target. Third-person cameras ride on critically damped springs so they catch up with the player without swinging past. Procedural secondary motion (antennae, tails, ponytails, a backpack bouncing on a character's back) is underdamped springs hung off the skeleton. Outside games the same equation is a car's suspension, a door closer, a robot joint under PD control and a needle gauge on a dashboard, all tuned by choosing .