logo
By Lawrence

15 minutes

Enemy Drivers

Series 1 left you on an endless highway, with traffic, trees you can hit, nightfall and sparks. Every car on it is polite. Civilians keep their lanes, and nothing chases you. Nothing can hurt you either, because your car has no health.

This lesson adds two kinds of enemy, the rammer and the shover, and gives you 100 hit points to lose.

One push and two cars

When two cars touch, the hit pushes both of them by the same amount, in opposite directions. How much a car's speed changes depends on its own mass:

dv = J ÷ m      J is the push, m the car's mass, dv its change in speed

A light car's speed changes a lot, and a heavy car's barely moves. Say a shover van swipes you from the side at 8 m/s. Your speed changes by 2.72 m/s. The van's changes by 1.10. It is the same push, but the van is 2.5 times heavier than you.

Two cars side by side with one push arrow between them, pointing both ways. Under each car a bar shows its change in speed: 2.72 m/s for your car, 1.10 m/s for the van, both short of a dashed line at 4 m/s where damage starts.

A small change in speed is free. Past 4 m/s, it starts to hurt:

damage = max(0, dv − 4) × 2.2 × (1 − armour) × the other car's ramDamage × damageTaken

Armour, CarCollision's armor field, is a shield. Only 1 − armour of the damage gets through, so your car's 0.15 lets 85% in. ramDamage is how hard the other car hits, and damageTaken scales every hit your car takes.

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