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.

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.
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
| Value | Start with | What it changes |
|---|---|---|
| maxSpeed | 22 units/s | The fastest the vehicle goes in any direction. It counts the slide too, or a drifting vehicle ends up faster than a straight one. |
| accel | 20 units/s² | How hard full throttle pushes. At this value the vehicle reaches drift speed in about half a second. |
| drag | 0.8 1/s | How fast the vehicle slows down with no throttle. It stops the vehicle rolling for ever. |
| turnRate | 2.4 rad/s | How fast the nose turns at full steering. A little over a third of a full circle per second. |
| driftTurnBoost | 1.4 | How much quicker the nose turns during a drift. It lets the player rotate into a corner, which is much of the point. |
| gripNormal | 12 1/s | How fast sideways speed dies while the tyres hold. At this value a slide is gone in about a quarter of a second. |
| gripDrift | 1.6 1/s | The same while drifting. Low values give a long, wild slide, high values a short and tame one. Zero never lets the slide die. |
| gripChange | 100 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. |
| driftStartSpeed | 8 units/s | The speed needed to start a drift. Below it the handbrake only slows the vehicle, because a slow slide looks like a bug. |
| driftEndSpeed | 4 units/s | A 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
- Your vehicle drives at 15 units per second. The player holds the handbrake: A drift starts.
- Your vehicle drives at 5 units per second. The player holds the handbrake: No drift starts and the grip stays as it was.
- Your vehicle slides sideways at 6 units per second while driving forward. A second passes with the tyres holding: The sideways speed is almost gone.
- Your vehicle drives straight with its nose turned a little to the side. A third of a second passes, once with the handbrake and once without: With the handbrake it still slides clearly sideways, without it the slide is gone.
- Your vehicle is in a drift. The player lets go of the handbrake: Grip starts to come back but is not at full on the first tick, and gripping resumes only once it is full.
- Your vehicle drifts and has slowed to 3 units per second. The handbrake is still held: The drift ends.
- Your vehicle drives at 6 units per second, between the end speed and the start speed. The handbrake is held, once while drifting and once while gripping: The drifting vehicle keeps drifting, the gripping vehicle does not start.
- Your vehicle has full throttle for fifteen seconds and steers left and right with the handbrake going on and off. You look at its speed on every tick: It never goes over the maximum speed.
- A parked vehicle, and one rolling at 15 units per second. Both get full steering: The parked one does not turn, the rolling one turns at the turn rate.
- Your vehicle rolls backwards. The player steers to the positive side: The nose turns to the negative side.
- Two vehicles at the same speed, one drifting. Both get full steering for one tick: The drifting one turns by the boost factor more.
Works well with
- Stamina System: Our tests here do not cover the two together. Spend a little of a boost meter during the drift, and give it back when the drift ends.
- Knockback: A hit then sends the vehicle sideways and the grip pulls it back into line. Apply the push to the real velocity, not to the nose direction.
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.
What was checked
- 16 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
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