logo
By Lawrence

13 minutes

Sparks and Screen Shake

Clip a tree at 30 m/s and the car spins 132°. It is a huge crash, and the game acts as if nothing happened. No spark, no dust, and the camera never blinks.

RoadFX draws every crash. It also gives RoadCamera's shake its first hits, so a big one lands in your hands.

Trauma

A shake needs a size. RoadCamera keeps one number for it, trauma, from 0 to 1. Every hit adds to it, and time drains it at 1.6 a second. The camera moves by trauma squared, times shakeMax, which is 1.4 m:

shake size = trauma² × 1.4 m

Squaring keeps small numbers small and lets big ones through:

trauma   trauma²   shake size
0.1      0.01      0.014 m
0.29     0.08      0.11 m     a 10 m/s tap on a tree
0.8      0.64      0.90 m     a 28 m/s crash

On screen the tap moves the view 1.1 px and is gone in 0.17 s. The crash moves it 15 px and shakes for half a second.

A chart of shake size against trauma from 0 to 1. A straight line climbs from 0 to 1.4 m. A curve hugs the floor at first, then bends up to meet it. A tap at trauma 0.29 sits on the flat part of the curve; a crash at 0.8 sits high on it.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search