05 / Camera
Screen shake
trauma squared, smooth noise
A camera that jumps to a random spot each frame after an impact looks like a glitch. A convincing shake sways, and scales with how hard the hit was. One well-known recipe treats shake as damage the camera absorbs: impacts pile up a trauma value, time bleeds it away, and the camera is offset by smooth noise scaled by the square of that value. Try a small and a big hit, and compare the trauma line with its square, which drives the camera.
- Explosions, ground pounds and heavy landings
- Damage to the player, so it registers
Prompts to paste
Explosions and big hits need more punch. Each frame, offset the camera's position and roll by smooth noise (Perlin or simplex, sampled at about 20 Hz) scaled by trauma² and a maximum offset. Keep trauma between 0 and 1: take off roughly 1.2 × dt every frame, and add 0.2–0.7 on each impact, by its size.
Add a camera shake component driven by trauma. Expose AddTrauma(amount); trauma stays within 0–1 and drains linearly at 1 per second. Each frame compute shake = trauma * trauma, then offset the camera locally: x and y by maxOffset * shake * noise, and roll by maxRoll * shake * noise, where each axis samples its own smooth noise (Perlin or simplex, a different seed per axis) at time * 20. Put the offset on a child transform of the follow camera so the two don't fight, and add a setting that scales the shake down or switches it off.
Examples
Why square it
With trauma squared, a 0.3 hit moves the camera 9% of the maximum and a 0.9 hit 81%. Light hits stay readable; heavy ones feel heavy.
Roll is cheap drama
In 3D, a degree or two of roll reads as more violent than a large sideways offset, and keeps the target in frame.
Where the idea comes from
Trauma-driven shake was popularised by Squirrel Eiserloh's GDC talk on juicing cameras with math, which is a good search for more detail.
Pitfalls
Fresh random offsets each frame
The camera jumps to a new spot 60 times a second. It looks like a glitch rather than an impact, and it's tiring to watch.
No off switch
Shake can make some players feel unwell. Provide a slider or an off option, and follow the system's reduced-motion setting.
Unbounded trauma
Without a cap, a burst of hits throws the camera far off target. Clamp at 1 and let the squaring handle the scale.
Starting values
| Setting | Value | Note |
|---|---|---|
| Trauma for a small hit | 0.2–0.3 | |
| Trauma for a big hit | 0.6–0.8 | |
| Drain | 1–1.5 per second | |
| Max offset | 10–20 px in 2D, 0.2–0.5 units in 3D | |
| Max roll | 1–3° |