logo
By Lawrence

9 minutes

Follow Camera

Floor it and watch the top of the screen. However fast you go, you see the same 37 m of road ahead. At top speed a bend is under your wheels 0.71 s after it shows up.

The camera is nailed to the car. Lesson 1.1 put three fields on RoadCamera to do that. This lesson pulls them out, and shows the one direction a camera must never be smooth.

Chasing a moving car

The usual way to smooth a camera is one line, run every frame: close a share of the gap to where you want to be.

camera += (want - camera) * k

That line is a lerp, short for linear interpolation: moving a share k of the way. Point that at a parked car and it glides in. Point it at a moving car and it never arrives. It settles a fixed distance behind, where the bit it closes each frame equals the bit the car moves. That distance is speed ÷ rate. Our camera's rate is 4 per second, which means it closes in at four times the gap each second. From 1 m behind, it moves at 4 m/s. To keep pace with a car at 52 m/s, it has to sit 13 m behind.

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