Logs / Route 004

Simulate the parts, not the behaviour

The one idea behind all the physics in Sandbox Drive, and a quick tour of where it leads, from the tyres to the gearbox to the steering wheel in your hands.

·3 min read·6 sections

A night test drive, earlier this summer

There are two ways to make a car feel right in a game. One is to decide how it should behave (how much it understeers, how quickly it spins, how it feels on gravel) and tune a model until it does that. The other is to simulate the parts that make a real car behave that way, and let the behaviour come out of them.

Sandbox Drive does the second. It’s slower, it breaks in stranger ways, and a lot of the time the answer to “why does it do that?” is “because a real one would”. But when it works, cars do things nobody told them to. A car with an open differential spins its inside wheel out of a tight hairpin, and there’s no line of code anywhere that says so.

This is a quick tour. The tyres get their own post, because they deserve it.

The tyres

Everything a car does, it does through four patches of rubber about the size of a hand. The tyre model treats the contact patch as a brush of tiny rubber bristles that stick to the road, stretch and eventually slide. The tyre behind it flexes, so grip builds up over a short distance instead of arriving instantly, which is why a car feels slightly lazy the first moment it turns in. The rubber heats up and grips differently hot and cold. The air inside heats too and raises the pressure. Rain costs grip at any speed, and deep standing water can lift the tyre right off the road.

Soft ground

Off the tarmac, the ground stops being a surface and becomes a material. A wheel on soft ground sinks, the rut it digs costs power to climb out of, and the soil can only take so much shear before the wheel just spins. Letting air out of the tyres spreads the load over a longer patch, and sometimes that’s the difference between getting up a slope and becoming part of it.

Between the engine and the wheels

This is the bit most games skip. Clutches have a bite point, slip, and get hot when they’re ridden on a hill. There’s a manual gearbox with a pedal, a sequential, a dual-clutch that creeps like a real one, an automatic with a torque converter, and single-speed electric. Differentials are open, limited-slip or locking, which is why that open diff sends everything to the wheel with the least grip. Turbos lag and spool, superchargers whine, and a hybrid module can add electric shove on top.

ABS, traction control and stability control are there for anyone who wants them, and switch off for anyone who doesn’t.

What you feel through the wheel

On a steering wheel, the force comes from what the front tyres are doing: how hard they’re pulling back towards straight, plus the geometry of the steering axis. That pull fades as the tyres reach their limit, so the wheel goes light just before the front of the car washes wide. It’s the most useful warning a car gives, and it comes out of the tyre model for free.

The low-speed feel is still being tuned, and that needs a person with an actual wheel in their hands rather than another test script.

Crashes

A crash deforms the body using crush data from real crash tests, so the front of a car folds the way fronts fold. Knock a wheel hard enough and it stays bent (toe and camber that won’t come back without a repair), or comes off entirely. Big hits bend the whole chassis. Engines can give up after a bad one. The tow truck exists for a reason.

Making it fast enough

All of this runs for every car on the island, every physics step, and that adds up. So the whole vehicle model is being ported from Godot’s scripting language to native C++. The rule for the port is that the native car has to drive exactly like the original, bit for bit, across a fleet of test cars, before it’s allowed to replace anything. The electric cars aren’t ported yet.

AI traffic already runs on it. The player’s car follows once the last pieces pass the same test, including handing a car between two players in multiplayer. The point of all that care is simple: the port shouldn’t change anything you can feel. It should just let more cars share the island.

Filed under physics, vehicles

Photo mode1 / 1