📚 Encyclopedia

Games & Graphics · updated 2026-10-13

Arcade vehicle handling, handbrake drift and vehicle architecture

vehicle-physicsdrifthandbrakegame-designoopcomposition

Design notes for top-down arcade car handling: a handbrake that fishtails and drifts, weight that changes how a vehicle interacts with the world, and a class structure where each vehicle draws itself. From Spacebar (Flutter build, 2026-03; the design carried into the JS rebuild).

Handbrake and drift

Weight matters everywhere

One weight value scales every world interaction: - Terrain modifier: effective = 1 + (modifier - 1) / weight (a tank barely slows in sand, a light racer gets the full effect). - Barrier break threshold: threshold / weight. - Impact damage: damage / weight. Heavy vehicles should also resist drifting and light ones slide more (tune drift thresholds by weight).

Damage as visuals, not handling

Keep handling intact as health drops; the health bar is the penalty. Show damage visually in stages: glow flickers, then smoke, sparks, a darkened body.

Class structure: vehicles draw themselves

World elements taxonomy

A useful split for what vehicles collide with (Spacebar structural elements, about 40 to 60 per zone): - Hard barriers (building walls, containers, pillars, jersey barriers): bounce plus damage. - Soft barriers (guardrails, signs, lamp posts, fences): break through or deflect by speed and angle. - Terrain modifiers as sensor areas that alter physics while overlapping: sand 0.6x speed, water 0.5x speed plus 2 damage/s, oil 0.2x traction, gravel. Apply them to AI cars too. - Scenery in background (tire tracks, debris, markings) and foreground (billboards, canopies) layers, with zero per-frame cost. Shapes as a sealed hierarchy (rect, circle, polygon, polyline, compound) that each provide bounds, a path, hitboxes and a contains test; cache paths and paints and cull by precomputed rects.

Breakable barriers

Soft barriers (guardrails, signs, lamp posts) break or deflect depending on speed and impact angle. Watch the angle convention: one implementation used acos (0 = head-on) against thresholds that assumed pi/2 = head-on, so glancing hits broke through and head-on hits bounced; switching to asin fixed it. Broken barriers stay broken and are persisted in the save (see Earned, not given (designing conveniences as gameplay)).

Port to a browser game: Joyride (justinahampton.com arcade, 2026-09)

Joyride, a top-down GTA2-like single-page game, ported Spacebar's drift model to plain JS and added a few lessons of its own. - Slip angle model. The car stores slip (radians); travel direction = heading + slip. Grip realigns slip quickly (12/s); the handbrake (Space) locks the rears: deceleration 110 px/s², realign only 2/s, 90% of steering transferred into slide (the nose turns, travel keeps going), handbrake steer 1.3x, drag 0.5 per radian of slip, max slip 1 rad (57 degrees). Constants were scaled down from Spacebar's because that game's speeds are about 2x. Skid marks at the rear wheels only while |slip| > 0.22, capped at 600 dots. - Steering falloff at speed (STEER_FALLOFF 0.7 of authority at top speed). Without it the grip turn radius (73 px) was already tighter than the 80 px road, so the handbrake had nothing to beat. Measured after: compact car 90-degree corner on grip r of about 104, handbrake r of about 68 with exit speed 164 vs 240 in one second. - Grind along walls instead of stopping. On wall contact compute severity = (velocity into the wall) / speed, the sine of the approach angle. Below 0.72 (about 46 degrees) keep the along-wall component, hold the slip for 0.08 s so grip does not steer the car back in, and scrub speed by 2.5 x sin|slip| per second while grinding (settles 240 to ~190 at 25 degrees, ~125 at 44, full speed at 10). Steeper hits use the old halt (v * cos² * 0.85). Sparks every 0.05 s above 90 px/s. Justin's spec: "slow and grind along obstacles rather than coming to a halt", cut off around 45 degrees. - Car-to-car collisions: scrub only the approaching component. Multiplying the whole velocity of both cars by 0.55 on every frame of contact meant a cop bulldozing the player re-collided every frame and pinned a reversing player at ~0 speed (and steering authority scales with speed, so no escape). Removing only the velocity component heading into the other car, projected back onto the travel line, leaves a retreating car untouched: reverse for 1 s went from -4 to -96 px/s. Head-on hits are unchanged; glancing touches barely slow you. - Population is a ring around the player, not the map. Spawning uniformly over the whole map and keeping only spawns 420 to 1500 px away collapsed in density as the map grew. Spawn cars at road nodes and pedestrians on walkable cells inside a ring (420 to 1100 px), cull anything beyond 1400 px, and entity counts (and frame cost) become independent of map size. Measured: 0.15 to 0.17 ms per frame for update + draw at both 7x7 and 14x14 blocks; the only per-frame cost that grows with the map is a minimap block loop (cache it to an offscreen canvas if it grows past ~16). - Death as a state, not a call up the stack. The combat module marks the player dead; the game loop notices and runs the "wasted/busted, -$100, respawn at the hospital or police lot" sequence. That keeps lower layers from importing higher ones.

See also

Linked from

Sources: spacebar memory (project_handbrake_drift, project_vehicle_redesign, feedback_vehicles_draw_themselves, project_structural_elements), justinahampton memory (arcade-joyride, joyride-architecture)