logo
By Lawrence

13 minutes

The Player Car

The interceptor sits on the road like a picture of a car. Press W and nothing happens. And a car is not a walking character: press left on a walker and it steps left, but press left in a car and only the nose turns.

Nose and momentum

Turn the wheel and the nose turns. The momentum does not. The car keeps going the way it was going, and the tyres drag it round to the new nose. While they work, the nose and the travel point different ways. That gap is a slide.

So every frame, the game splits the car's velocity (its speed and direction together) in two: the part along the nose, and the part sideways. The pedals work on the first part. Grip works on the second, and all it can do is shrink it:

A car seen from above. Its nose points up and to the right, but its velocity arrow still points straight up. The velocity splits into a long part along the nose and a short part sideways, and grip shrinks the sideways part.

new slide  =  old slide × (1 − grip) to the power of (dt / 0.1)

dt is the seconds since the last frame, about 0.017 at 60 frames a second. grip is the share of the slide the tyres scrub off every tenth of a second. Start with a 10 m/s slide and wait 0.1 s:

grip 0.9    1 m/s of slide left
grip 0.3    7 m/s left
grip 1.0    0 m/s left: the car runs on rails

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