Organic Motion: Noise, Wobble and Screen Shake
Things look alive when they wobble without a visible pattern. You can get that by adding sines whose frequencies never line up, or by blending random numbers with a smoothstep. Screen shake then scales that wobble by trauma squared, so small hits barely register, big ones really shake and every shake fades out smoothly instead of stopping dead.
What the symbols mean
- Amplitude
How big each wiggle is; usually smaller for faster ones.
- Frequency
How fast each wiggle goes, in radians per second. Pick ratios that aren't simple fractions.
- Phase
Where each wiggle starts, so they don't all begin together.
What the symbols mean
- Lattice value
A random number fixed at each whole number i, from a hash so it's the same every time.
- Fade
Smoothstep of the fraction f: eases out of one lattice value and into the next.
What the symbols mean
- Maximum offset
The biggest the shake can ever be: pixels of offset, or degrees of roll.
- Trauma
A number from 0 to 1. Hits add to it, and it falls steadily back to 0.
Explanation
Noise, in animation, is simply a smooth, random-looking wobble: a function of time that wanders up and down with no pattern your eye can catch, used to make things feel alive instead of mechanical. The name comes from signal processing, where noise means any random signal, but the noise of games and film is smooth, closer to a breeze than to TV static. It's how a torch flickers, a hovering drone drifts, a hand-held camera sways and the screen shakes when something explodes. The three formulas in the box look like three separate ideas, but each is only a few small parts: some sines added together, some random numbers joined by a smoothstep and a "trauma" number squared to decide how hard to shake. Each one is two or three lines of code; bear with them.
Sums of sines. One sine is a metronome. Within a couple of seconds your eye catches the repeat and the "random" sway looks like a machine. So add a few sines with different frequencies. The catch is that if the frequencies are in a simple ratio, the sum repeats too. Take : the first repeats every , the second every , and both line up again at (two of the first, three of the second), so the sum repeats every . The fix is frequencies whose ratio isn't a fraction at all, like and , or and the golden ratio . Then no time is a whole number of both periods, and the pattern never exactly comes back. Give faster wiggles smaller amplitudes (halving the amplitude each time the frequency roughly doubles is a classic choice) so the motion has big slow drifts with fine trembling on top.
Value noise. Another way to get a smooth random function: put a random number at every whole number , then fill in between. The random numbers come from a hash, a function that scrambles into a number that looks random but is the same every time you ask, so the wobble can be replayed. Now, how to fill in between?
A plain lerp, , works but has corners. Its slope on each stretch is , a different number on every stretch, so the slope jumps at every whole number, and the motion visibly jerks there. Swap for the smoothstep from Smoothstep and Smootherstep. By the chain rule the slope becomes
and is at both and . So the slope arriving at each whole number is , and the slope leaving it is : no corners. The tangent line in the animation further down shows the difference. Notice the price: value noise is flat at every whole number, which can show up as a faint regular rhythm. Ken Perlin's gradient noise fixes that by storing a random slope at each whole number instead of a value, and uses the smootherstep so the curvature is continuous too. Adding copies at double the frequency and half the amplitude (octaves) gives the rich, fractal look of terrain and clouds.
const hash = (i: number) => { // a scrambled number in [-1, 1], the same every time for the same i
const s = Math.sin(i * 127.1) * 43758.5453;
return 2 * (s - Math.floor(s)) - 1;
};
function valueNoise(x: number) {
const i = Math.floor(x), f = x - i;
const s = f * f * (3 - 2 * f); // smoothstep fade
return hash(i) + s * (hash(i + 1) - hash(i));
}
Trauma-based screen shake. This approach, popularized by Squirrel Eiserloh's talk on game cameras, keeps one number per camera: trauma, between and . Every hit or explosion adds to it (capped at ), and it falls back toward at a steady rate. Each frame, the camera's offset and roll are
with a different noise channel (a different seed) for , for and for the roll angle.
Why noise and not a fresh random number every frame? A random number per frame is pure static: it jitters harder the higher the frame rate, a 144 Hz monitor shakes differently from a 60 Hz one, and nothing can be replayed. Noise sampled at the current time is smooth, the same at any frame rate and repeatable.
Why squaring trauma feels right. Two reasons, one about size and one about timing.
- Size. Squaring spreads small and large hits apart. Trauma gives shake ; trauma gives . Doubling the trauma quadruples the shake, so a pistol barely nudges the camera while a grenade rattles it, which is how people expect it to feel.
- Timing. Trauma falls linearly, . Its square, , has slope , which shrinks to exactly as the trauma runs out. So the shake fades out with zero slope, an ease-out you get for free, while unsquared trauma would hit at full speed and the shake would stop dead. Cubing makes it gentler still.
trauma = Math.max(0, trauma - decay * dt); // hits do: trauma = Math.min(1, trauma + amount)
const shake = trauma * trauma;
camera.x = rest.x + maxOffset * shake * noise(seedX, speed * time);
camera.y = rest.y + maxOffset * shake * noise(seedY, speed * time);
camera.roll = maxRoll * shake * noise(seedR, speed * time);
A common mistake. It's tempting to shake the camera with Math.random() each frame because it's random and that's what shaking is. But it ties the shake to the frame rate and makes it harsh static. Sample smooth noise at the current time instead.
A common mistake. It's tempting to reuse one noise channel for both axes, since noise is noise. But then and move in lockstep and the camera only ever shakes back and forth along one diagonal line. Each axis, and the roll, needs its own seed.
A common mistake. It's tempting to write the shake as camera.x += ..., nudging the camera a little each frame. The nudges then pile up and the camera drifts away from where it should be. Shake is an offset recomputed every frame on top of the resting position, exactly as in the code.
Noise also pairs with everything earlier in this course: the trauma could just as well decay smoothly (Smoothing That Doesn't Depend on Frame Rate), a camera can be kicked and then spring back on a damped spring (Springs: Bouncy, Critical and Sluggish), and an idle character can breathe by adding a little noise to its pose.
See it
Worked examples
Value noise has lattice values and . Find with the smoothstep fade, compare it with plain lerp and find the slope .
- 1
Find the cell: and , a quarter of the way from to .
An explosion sets a camera's trauma to . Trauma falls at per second, the shake is trauma squared, and the maximum offset is px. Find the shake's offset amplitude at s, when the shake ends and how fast the amplitude is changing at the moment it ends.
- 1
Write the trauma as a function of time: , until it reaches .
A lantern sways by . How often does the sway repeat?
- 1
Find each sine's period: repeats every and every .
Practice
Type your answer and check it. Solve them all to complete the lesson.
A flag's flutter is driven by . What is the shortest time after which the flutter repeats exactly?
One-dimensional value noise uses the smoothstep fade , with lattice values and . Find .
In a game, a crash sets the camera's trauma to . Trauma falls at per second, and the camera's roll is times trauma squared times a noise value between and . What is the largest roll possible (in degrees) s after the crash?
A hit sets trauma to , and trauma falls at per second. The shake is trauma squared. How many seconds after the hit has the shake dropped to a quarter of its starting value?
Why do trauma-based shake systems square the trauma instead of using it directly?
Noise built with the smootherstep fade has lattice values and . Find its value a quarter of the way between them, .
A camera's trauma decays smoothly instead of linearly: with , and the shake is . How many seconds until the shake falls to of its starting value?
Which hovering motion never exactly repeats?
The hardest one here. Get it, and you've got this lesson.
A screen shake moves the camera by px, where trauma and is smoothstep value noise with lattice values and . Find the camera's velocity in px/s.
Where it's used
Trauma-based shake is standard in action games: explosions, landings and hits add trauma, and translation plus roll driven by smooth noise sell the impact without making players sick. Film previsualization and virtual cameras add a little noise to fake a hand-held operator. Idle animations breathe and sway with low-frequency noise so a character standing still doesn't look frozen, and flames, flickering lights, wind in grass and bobbing buoys all run on sums of sines or noise. In two and three dimensions the same value and gradient noise generate terrain heights, clouds, marble and wood grain.