Tutorial Β· 5 steps Β· driving kit

Make an endless driving game with AI

Did you ask an AI for a driving game and watch the road end in a grey wall after ten seconds? Or get a car that drives off the edge of the world? An endless driving game builds new road ahead of you and throws away the road behind, for as long as you keep driving. The camera and the traffic have to keep up with the car the whole time. Ask for all of it in one prompt and something slips.

The driving kit has all of that working. A small car drives an endless road through low-poly hills at golden hour. Steer around the oncoming cars and keep your foot down. Your score is the distance you cover before a crash, and the car drives itself on the title screen while it waits for you. It's one file of three.js and it runs on a phone. The five prompts below turn it into Snowline, a drive over a snowy mountain pass at dusk. Swap in your own road as you go.

Slow Roads set the shape of the endless drive in 2022, and it was made by hand. Metro Drift on this shelf takes the car into night traffic, where skimming past other cars refills your nitro.

Step 1: Change the road and the sky

Read index.html. It is a three.js endless driving game: a small car drives an endless road through low-poly hills at golden hour, oncoming cars come the other way, and the score is distance driven. Change the world to a snowy mountain pass at dusk: white hills with grey rock, a deep blue sky, dark pine trees along the road and light snow falling. Keep everything in index.html and add no new libraries.
What you see

the same car and the same traffic, now climbing through white hills under a deep blue sky. Snow drifts down across the screen.

If it goes wrong

the snow drops the game to a crawl on your phone. The AI made every snowflake its own object. Paste this:

The snow slows the game down on my phone. Draw all the snowflakes as one Points object with at most 1,500 points, and move each flake back to the top when it falls below the camera.

Step 2: Make the car slide on snow

Make the car handle like it is on snow. Steering builds up over half a second and eases off when I let go. Above 80 km/h a hard turn lets the back of the car slide wide, and it grips again when I straighten up. Show the speed in km/h in a small HUD in the top left corner.
What you see

the car turns in a moment late, and the tail swings out when you turn hard at speed. The number in the corner climbs as you speed up.

If it goes wrong

the car keeps sliding after you let go and spins off the road. Paste this:

The car keeps sliding after I let go of the steering. Bring the slide angle back to zero over about half a second whenever I am not steering, and never let it go past 25 degrees.

Step 3: Score the near misses

Keep the score as distance driven, and add 50 points each time an oncoming car passes within one car's width of mine without a crash. Flash "Close!" next to my car when it happens. Every 2 km, make the oncoming cars a little faster and closer together.
What you see

"Close!" pops up when you skim past a car, and the score jumps by 50. After 2 km the traffic comes thicker.

If it goes wrong

one car pays you the bonus five times as it goes by. The game checks the gap on every frame while the cars are side by side. Paste this:

One car pays the near-miss bonus several times. Give each oncoming car the bonus at most once, at the moment it passes the back of my car.

Step 4: Add sound

Add sound with the Web Audio API only, no audio files. An engine note whose pitch rises with speed, a short whoosh each time an oncoming car passes, and a crunch on a crash. Start the audio on the first tap or key press, and add a mute button in the top right corner that remembers its setting in localStorage.
What you see

an engine that climbs as you speed up and a whoosh every time a car goes by. Mute it, reload, and it stays muted.

Want a crunch of your own? Make one in the sound effect maker and copy it as code. It plays with no audio file.

If it goes wrong

the engine keeps running after a crash, under the title screen where the car drives itself. Paste this:

The engine keeps playing on the title screen. Fade the engine out over half a second when a run ends, and only play it while I am driving.

Step 5: Add a title and a share line

On the title screen, where the car drives itself, show the name Snowline, a Play button and the best distance so far, saved in localStorage. After a crash, show this run's distance next to the best, with Drive again and Share buttons. Share uses navigator.share when it exists and copies "I drove 3.2 km on Snowline" with the page address when it doesn't.
What you see

Snowline over the road before your first run, and your best distance waiting there when you come back. On a phone, Share opens the share sheet.

Want a pixel car beside the name? Draw one in the pixel sprite maker and press Copy as code. The game still needs no image file.

If it goes wrong

Drive again puts you back inside the car you crashed into. Paste this:

Drive again starts me inside the car I crashed into. At the start of every run, remove all oncoming cars and put my car back on a clear stretch of road at the starting speed.

Where makers took it

Slow Roads, endless driving through misty hills

Slow Roads

Endless driving through misty procedural hills since 2022. It's made by hand, and it's the bar the AI games are chasing.

@anslogenSee the game
Metro Drift, drift through night traffic to the finish

Metro Drift

Race the Night Port or Overpass route and hit checkpoints to add time. Drift and skim past cars to refill your nitro.

Put it on the shelf

Got a road your friends want to drive? Get the game a public link with the hosting tutorial, then send it to us. Listing is free. Your game gets its own page and a place on the driving games shelf.

Submit your game

FAQ

How does an endless driving game keep making road?

The kit builds new road a short way ahead of the car and removes the road behind it. The game only ever holds a short stretch, so an hour in it runs as smoothly as it did at the start. If your version slows down the longer you drive, ask the AI to remove road pieces and cars once they fall behind the camera.

Will my driving game work on a phone?

The kit does. You drag to steer, and it keeps 60 frames a second on a mid-range phone because it skips shadows and post-processing. Drive on your phone after each prompt. A slow phone feels the snow from step 1 first.

Can I turn the driving kit into a racing game?

Yes. Ask the AI for a finish line and a timer, with checkpoints that add time. Metro Drift plays that way. For rivals, ask for a few cars that drive your way at a steady pace for you to pass.