How to make a racing game with AI
A racing game is one car, three numbers and a lap counter. Get the three numbers right and even a rectangle on a grey track feels good to drive.
Jump to a section
Ask for a top down racer in one file: one car, one track, three laps, and a best time kept between sessions. Then spend your time on how the car turns, because that is the entire game. Three dimensions can wait, and usually should.
A 3D racer needs a track mesh, a camera, collision against the scenery and a car that does not sink through the road. A top down racer needs a car and a mask of where the road is. The driving feels identical to tune, and one of them exists tonight.
Four steps to a car you want to drive#
Claude, ChatGPT and Gemini all handle this one well. It is a small amount of maths and a lot of tuning.
The question is not whether it works. It is whether turning feels like driving or like dragging a mouse pointer.
Grip, turn rate, acceleration. Change one, drive a lap, decide. Changing two tells you nothing about either.
Corners, a second lane, a wall, a rival car. All of it is wasted on a car that is unpleasant to steer.
Build a top down racing game as ONE self-contained .html file. No
frameworks, no images, no 3D.
TRACK: a closed loop seen from above, drawn with canvas shapes. Grass
outside, tarmac inside. Driving on grass halves the top speed. The view
scrolls to follow the car and the car stays near the centre.
CAR: a rectangle with a nose. Up accelerates, down brakes and reverses,
left and right steer. Steering only turns the car while it is moving.
HANDLING: keep velocity as a vector. Each frame, split it into the part
pointing along the car and the part pointing sideways, and bleed the
sideways part away according to a GRIP value. Low grip should slide.
LAPS: four checkpoints around the loop. A lap only counts when all four
have been crossed IN ORDER, so cutting the track does not score. Three
laps to finish. Show current lap time, last lap and best lap.
SAVING: best lap goes in localStorage and survives a reload.
PHONE: tapping the left or right half of the screen steers, and the car
accelerates by itself.
Base everything on seconds elapsed between frames, capped at 0.05. Put
GRIP, TURN_RATE, ACCELERATION, BRAKE and MAX_SPEED in one CONFIG object
at the top with a comment on each.
The handling paragraph is the whole game. Without it you get a car that pivots on the spot like a tank, which is the single most common thing a first racing build gets wrong.
The three numbers behind how a car feels#
Every complaint about a first racing build comes back to one of three values, and the fastest way to learn which is to push each one to an extreme on purpose.
| It feels like | The number | Ask for |
|---|---|---|
| A tank pivoting on the spot | Turn rate is applied while stopped | Steering scaled by current speed |
| Driving on rails, no weight | Grip is too high | Less grip, so the back steps out under power |
| Skating on ice, no control | Grip is too low | More grip, and slightly slower steering |
| Floaty, slow to respond | Acceleration is too low | Faster acceleration and a lower top speed |
| Over before the first corner | Top speed is too high for the track | A longer track, or a lower top speed |
Describe the feeling, not the value. The model can see the whole config, and you can feel the car.
Why your lap times are wrong on another machine#
Racing is the genre where frame rate dependence stops being invisible. A car moved by a fixed amount per frame is twice as fast on a 120Hz screen. A best lap set on a gaming laptop is then unbeatable on a phone, and the leaderboard means nothing.
The cap matters as much as the delta. Without one, a tab left in the background returns with a gap of several seconds, and the car teleports through the wall it was about to hit. Capping the step at 0.05 seconds keeps the worst case to one frame of overshoot.
Laps, checkpoints and cutting the track#
A lap counted by crossing the start line is a lap counted wrong. The player reverses over the line three times and finishes the race without driving. On a track with a hairpin they can cut a third of it and still score.
- Four checkpoints, crossed in order. Keep an index of the next expected one. Crossing any other does nothing. The lap counts only when the player returns to the first.
- Make them wide. A checkpoint should span the whole width of the road and a little beyond. A player who clips the grass on a corner should not have the lap silently voided.
- Show the next one while testing. Ask for a debug key that draws the checkpoints. Half an hour of confusion ends the moment you can see them.
- Time the lap from the crossing, not the key press. Otherwise the first lap includes the moment you spent working out which key accelerates.
🏁Racing games written by AI
Common questions#
Can AI make a racing game?
Yes. A top down racer with laps, lap times and a saved best is one prompt and a browser. The work is not the code. It is tuning the three numbers that decide how the car turns, which is the same job in any racing game ever made.
Why does my car spin on the spot like a tank?
Steering is being applied regardless of speed. Ask for the turn rate to be scaled by how fast the car is actually moving, so a stationary car cannot rotate. This single change is the difference between a vehicle and a cursor.
How do I make the car drift?
Keep velocity as a vector, split it each frame into the part along the car and the part sideways, and bleed the sideways part away slowly. A high bleed is grip and a low bleed is a slide. Drifting is that one number, not a separate feature.
Should I build a 3D racing game instead?
Not first. A 3D racer adds a camera, a track mesh and collision against scenery, and none of that improves how the car feels. Build the handling top down, then rebuild the view in 3D if you still want to.
How do I stop players cutting the track?
Place four checkpoints around the loop and require them to be crossed in order before a lap counts. A lap counted by the start line alone can be scored by reversing over it, which is the first thing anybody tries.
How do I add a computer controlled opponent?
Give it the same car and a list of points around the track to steer towards, with a small random offset so it does not drive a perfect line. Do this after the player's car feels right, because a rival inherits whatever is wrong with the handling.
Where to go next#
When you have caught yourself driving one more lap, publish it. It gets a page recording the model, the prompt and the tokens behind it, and a leaderboard other people can take your best lap off you on.
The general method is in how to make a game with AI. If you do want the 3D version later, the 3D guide covers the camera and the scene. Prompts for common faults are in the prompt guide, and the racing games here are worth a few laps first.
Built something? Put it on Agent Games.
Publishing takes a file and a minute. Your game gets its own page listing the model, the prompt and the token count, and anyone can play it without signing up.
Read next