Three.jscannon-esTypeScriptWeb Audio
Controls
- W or the up arrow drives; S or the down arrow brakes, then reverses
- A and D or the left and right arrows steer; Space is the handbrake
- Hold E to winch to the nearest tree once a winch is fitted; R puts the truck back on its wheels (+5 s)
- On touch screens: steering paddles bottom left, gas, brake and winch bottom right
- Drag the scene to look around; P or Escape pauses
Needs WebGL. Without it the poster is shown. Respects the reduced-motion setting: steadier camera, no shake and fewer mud and water particles; the driving physics is the game and stays. Sound is off until you turn it on. Cash, parts and best times are saved in this browser.
Questions
How do I play Mudline?
Drive the truck from the depot to the camp without losing the crates on its bed. Every crate that arrives is paid, with bonuses for a fast and clean run; spend the money on parts in the workshop.
What do the upgrades do?
The engine adds torque, tyres add grip in mud and on rock and grow taller, suspension adds travel and lift, cargo rails keep crates on and add room, the winch pulls you out of a bog, and the snorkel lets the engine breathe in deep water.
Why did my engine stop in the river?
Water reached the air intake. Cross slowly, pick the shallow line, or fit the snorkel, which raises the intake above the roof.
Does the mud really deform?
Yes. Spinning tyres press the ground down where it is soft, both in the physics and in the terrain mesh, so ruts deepen as you drive through them.
Does it work on a phone and save progress?
Yes. Touch screens get on-screen steering and pedals, and cash, parts, permits and best times are saved in this browser.
How it’s built
A 3D off-road cargo game: drive a 4x4 pickup from the depot to the camp through mud, rock gardens, logs and a river ford with loose crates on the bed. Each crate that arrives is paid; the money buys parts in the workshop and permits for harder trails. Plain Three.js for the view and cannon-es for the physics; no models or image files, everything is generated in code.
Architecture
core/ is pure TypeScript with no engine imports: parts, trails and pay in config.ts, prices, payout and the physical tuning each part level gives in economy.ts, and the seeded terrain (height, mud, river and track centre as functions of x and z) in terrain.ts. A Vitest economy simulation checks that an average player can buy something every one to four runs until the shop is empty.physics.ts is the cannon-es simulation and nothing else: a heightfield for the whole map, a four-wheel RaycastVehicle, crates as loose boxes on the bed, static rocks, logs and tree trunks, water and the winch. It steps at a fixed 1/60 s; headless tests drive it with a simple autopilot.world.ts is the Three.js view: terrain mesh, river, forest, grass, rocks, depot, camp, the truck from truck.ts and particles from fx.ts. It owns the renderer, the loop and every GPU resource.index.tsx wires input, the HTML interface (workshop, jobs, HUD, touch pedals, results) and saves.
Decisions
- Ground that deforms: the terrain mesh has one vertex per heightfield sample. A tyre that turns in mud presses nearby samples down (up to a depth set by how soft the trail is) through
Heightfield.setHeightValueAtIndex, so the next wheel really drops into the rut; the view copies the same samples, darkens them and recomputes their normals a few times a second. - Mud is a field, not a material: per wheel the grip falls with the mud value under the contact point, and the whole truck feels drag in proportion. Better tyres keep more grip and lose less speed.
- Water: buoyancy, drag and a sideways current on the body and the crates. The engine breathes through an intake low behind the grille (raised a little by lift) or, with the snorkel, above the roof; water over the intake for 1.2 s stalls the engine and ends the run with salvage pay.
- Parts change the physics, not just numbers: wheel radius, suspension rest length, travel, stiffness and damping, friction, engine force, rail height (real collision walls around the bed) and winch reach and pull all come from
tuning(). - Every run pays something: crates times the trail's rate plus a time bonus and a clean-load bonus, or salvage for the distance covered when the run ends early.
- Reflections come from each trail's own sky, baked into an environment map when the trail loads, so paint, glass, the river and puddles mirror the time of day.
- The map is fenced by invisible planes and ringed by a coarse skirt of hills and forest out to the fog.
Mechanics
- Contracts pick the cargo: crates, fuel drums (cannon cylinders that tip and roll) or glass, which listens to its own collisions and breaks when the impact speed along the contact normal passes 3.4 m/s.
- Fuel burns with throttle and load; jerry cans on the line refill it. Low range with locked diffs trades top speed and fuel for pull and mud grip.
- Stars (all cargo, under par, no recovery) pay a one-time bonus; storms make mud slicker and pay 30% more; scrap off the line pays for detours.
- Rain streaks fall in the vertex shader inside a box that follows the camera, so 1,800 streaks cost one draw call and no CPU updates.
Performance
- One heightfield of 193 × 193 samples; trees, rocks and grass are instanced (three draw calls for thousands of objects); one point cloud for all particles.
- The sun's shadow box follows the truck, so shadows stay sharp with one 2048 px map (1024 on the low tier).
- The loop stops when the game is off screen or the tab is hidden; leaving the tab mid-run pauses it.