Spielerando

Vehicle Drift

A drift lets a vehicle point one way while travelling another. Split the speed into the part along the nose and the part across it, let grip wear down the sideways part, and drop the grip while the handbrake is held. Make grip a value that moves, not a switch, so slides start and end smoothly.

Also called: Drifting, Powerslide, Handbrake turn.

A small round-nosed hovercar slides sideways through a hairpin bend, its nose pointing inside the corner while two long curved pink skid streaks and orange sparks trail behind it.
Tumbleflux Harbour, an invented top-down hovercar racing game. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Vehicle Drift" to my game.

What it should do: Drifting makes turning a skill instead of a steering wheel: the player trades speed for a tighter turn and a long, controlled slide. It is the difference between a vehicle that feels like it is on rails and one that feels like it has weight.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> grip
  grip: Gripping
  drift: Drifting
  regain: Regaining grip
  grip --> drift: handbrake at speed
  drift --> regain: let go, or too slow
  regain --> grip: grip is full again
  regain --> drift: handbrake again
```

Use these starting values:
- maxSpeed: 22 units/s
- accel: 20 units/s²
- drag: 0.8 1/s
- turnRate: 2.4 rad/s
- driftTurnBoost: 1.4
- gripNormal: 12 1/s
- gripDrift: 1.6 1/s
- gripChange: 100 1/s²
- driftStartSpeed: 8 units/s
- driftEndSpeed: 4 units/s

Watch out for these common mistakes:
- Grip as a switch: Tell your AI: let the grip value move towards its goal at a set rate, never jump.
- Slide dies at the wrong rate: Tell your AI: shrink the sideways speed by e to the power of minus grip times the time step.
- The slide breaks the speed limit: Tell your AI: put the cap on the whole speed, not only on the forward part.
- Flicker at the threshold: Tell your AI: end a drift at a lower speed than the one that starts it.
- Spinning on the spot: Tell your AI: let steering grow with forward speed, from nothing at rest to full at a low speed.
- Backing up: Tell your AI: turn the other way when the vehicle moves backwards.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

Drifting makes turning a skill instead of a steering wheel: the player trades speed for a tighter turn and a long, controlled slide. It is the difference between a vehicle that feels like it is on rails and one that feels like it has weight.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

handbrake at speedlet go, or too slowgrip is full againhandbrake againGrippingDriftingRegaining grip
How it runs, as a diagram
  • Gripping → Drifting: handbrake at speed
  • Drifting → Regaining grip: let go, or too slow
  • Regaining grip → Gripping: grip is full again
  • Regaining grip → Drifting: handbrake again

Good starting values

ValueStart withWhat it changes
maxSpeed22 units/sThe fastest the vehicle goes in any direction. It counts the slide too, or a drifting vehicle ends up faster than a straight one.
accel20 units/s²How hard full throttle pushes. At this value the vehicle reaches drift speed in about half a second.
drag0.8 1/sHow fast the vehicle slows down with no throttle. It stops the vehicle rolling for ever.
turnRate2.4 rad/sHow fast the nose turns at full steering. A little over a third of a full circle per second.
driftTurnBoost1.4How much quicker the nose turns during a drift. It lets the player rotate into a corner, which is much of the point.
gripNormal12 1/sHow fast sideways speed dies while the tyres hold. At this value a slide is gone in about a quarter of a second.
gripDrift1.6 1/sThe same while drifting. Low values give a long, wild slide, high values a short and tame one. Zero never lets the slide die.
gripChange100 1/s²How fast the grip moves from one value to the other. If it jumps at once, drifts start and end with a jerk.
driftStartSpeed8 units/sThe speed needed to start a drift. Below it the handbrake only slows the vehicle, because a slow slide looks like a bug.
driftEndSpeed4 units/sA drift ends when the speed falls below this. Keeping it under the start speed stops a drift from flickering on and off at one speed.

What usually goes wrong

Grip as a switch

If grip jumps between the two values, the vehicle snaps straight the moment the handbrake is let go, and the sideways speed turns into forward speed in one frame. It feels like hitting a wall.

Fix: Tell your AI: let the grip value move towards its goal at a set rate, never jump.

Slide dies at the wrong rate

Multiplying the sideways speed by a fixed share each frame makes the slide last twice as long at half the frame rate.

Fix: Tell your AI: shrink the sideways speed by e to the power of minus grip times the time step.

The slide breaks the speed limit

The forward speed is capped, but the slide adds a sideways part. Together they are faster than the cap, and a drifting vehicle outruns a straight one.

Fix: Tell your AI: put the cap on the whole speed, not only on the forward part.

Flicker at the threshold

If one speed both starts and ends a drift, a vehicle at that speed switches on and off every frame.

Fix: Tell your AI: end a drift at a lower speed than the one that starts it.

Spinning on the spot

Steering that works at a standstill makes a parked vehicle spin like a top.

Fix: Tell your AI: let steering grow with forward speed, from nothing at rest to full at a low speed.

Backing up

With the same steering rule, reversing turns the nose the wrong way compared with the wheels, and steering feels flipped.

Fix: Tell your AI: turn the other way when the vehicle moves backwards.

How to check it works

Works well with

Clashes with Camera Look-Ahead: In a drift the nose and the real direction differ, so the camera may look ahead in the wrong one and the player cannot see where the vehicle is going. Give the camera the real direction of travel, not the way the nose points.

Common questions

what do i tell my ai to add drifting to a car game

Paste this: Add drifting: split the car's speed into a part along the nose and a part across it, shrink the part across by a grip value, and while the handbrake is held at speed let the grip move down to a low value. Move the grip, do not switch it.

how does drifting work in a racing game

The car points one way and travels another. Normally the tyres kill the sideways part of the speed within a fraction of a second. In a drift that grip is much lower, so the sideways part lasts and the car slides around the corner.

why does my car snap straight when i let go of the drift button

Your grip probably jumps back to full at once. Let it move at a set rate instead, so the sideways speed fades over a few frames.

why is my car faster when it drifts

The speed limit is probably only on the forward part, and the slide adds to it. Put the limit on the whole speed.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it