logo
By Lawrence

14 minutes

Civilian Traffic

The highway is empty. Traffic has to be there whenever you look, at any speed, and it must never pop into view. At rest the screen shows the road from 10 m behind your car to 37 m ahead. A car that appears inside that strip looks like a glitch.

Cars per hundred metres

So new cars come on far up the road, 110 to 240 m ahead. Once they fall 100 m behind, they go back to their pool, a stock of spare cars parked out of play. Both ends are well off screen:

A side view of the road in metres from your car. The screen covers -10 to +37 m. New cars appear between +110 and +240 m. A car more than 100 m behind, or 360 m ahead, goes back to its pool.

The first idea for how many cars is a clock: send one every so often. But the count on the road is the rate times how long each car stays, and that depends on you. Park, and each car drives off up the road and leaves. Drive at the traffic's own pace, and a car stays with you for good.

HighwaySpawner works from a density instead. It turns the length of the window into a target number of cars:

target = min(maxCivilians, round(aheadMax / 100 × civilianDensity × traffic(level)))

traffic(level) is 1 on level 1, where this series stays, and climbs a little with each level after that. With our scene's numbers:

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