🏎️ How to Make a Car Racing Game in Scratch

by sidiqul_akbar in Teachers > 9

23 Views, 0 Favorites, 0 Comments

🏎️ How to Make a Car Racing Game in Scratch

Making a racing game was one of those Scratch projects that looks simple at first, but becomes much more interesting once you start adding movement, speed, collisions, multiple tracks, and different car designs.

In this project, I created CAR RACING THROUGH TRACKS!!!, a Scratch racing game where the player can drive a car around different tracks, switch between tracks, change the car's appearance, and interact with different parts of the track.

The finished project includes three tracks, keyboard controls, a speed system, collision detection, different car designs, track-specific starting positions, and random track switching.

You can play the finished project here:

https://scratch.mit.edu/projects/1327140147/

I also made a full video tutorial showing how the project was created.

Supplies

Software

  1. Scratch — https://scratch.mit.edu/
  2. A computer or laptop with a keyboard
  3. Scratch project assets
  4. The CAR RACING public assets project

Main project components

  1. car sprite
  2. collider sprite
  3. TREES sprite
  4. Three track backdrops
  5. Multiple car costumes

Project links

  1. Main game: https://scratch.mit.edu/projects/1327140147/
  2. Public assets: https://scratch.mit.edu/projects/1327132133/

Set Up the Scratch Project

Start by creating a new Scratch project.

The project uses a few main elements:

  1. car — the player-controlled vehicle
  2. collider — used for collision detection
  3. TREES — contains the tree artwork for the different tracks
  4. Three backdrops — Track 1, Track 2, and Track 3

The same car sprite is reused across all three tracks. Its position and direction change depending on the selected track.

The project also uses a variable called speed to control how quickly the car moves.

Program the Car

The car is the main sprite responsible for gameplay.

First, create a variable called speed.

When the green flag is clicked, place the car at its starting position, set its direction, and give it an initial speed.

when green flag clicked
go to x: -179 y: -88
point in direction 0
set [speed] to 2

The speed variable makes it possible to change the car's movement speed later.

Add Forward and Reverse Movement

Now add keyboard controls for driving the car.

For forward movement, use the Up Arrow:

if <key [up arrow] pressed?> then
move (speed) steps

For reversing, use the Down Arrow:

if <key [down arrow] pressed?> then
move (-1) steps

The negative value makes the car move in the opposite direction.

Add Turning

The Left Arrow and Right Arrow control the car's rotation.

if <key [right arrow] pressed?> then
turn clockwise (5) degrees

if <key [left arrow] pressed?> then
turn counterclockwise (5) degrees

These controls run inside a forever loop, allowing the player to drive and turn continuously.

📷 Attach Screenshot 4 here.

Create the Speed System

The speed variable can also react to different areas of the track.

if <touching color ... or touching color ...> then
set [speed] to 0.5
else
set [speed] to 2

When the car touches one of the specified colors, its speed changes to 0.5.

Otherwise, the normal speed remains 2.

This gives different parts of the track different driving behavior.

Add Collision Detection

The game uses a sprite called collider to detect areas where the car should stop.

The basic collision logic is:

forever
if <touching [collider]?> then
set [speed] to 0

When the car touches the collider, its speed is set to zero.

Add Multiple Tracks

The game contains three different tracks.

Each track has a different layout, so the car needs a different starting position and direction.

For Track 1:

when backdrop switches to [track 1]
go to x: -179 y: -88
point in direction 0

For Track 2:

when backdrop switches to [track 2]
go to x: 179 y: 88
point in direction 180

Track 3 also has its own starting position and direction.

In the project, Track 3 uses:

when backdrop switches to [track 3]
go to x: 71 y: 22
point in direction 0


Change the Track Environment

The TREES sprite has different costumes for the three tracks.

For example:

when backdrop switches to [track 1]
switch costume to [costume1]

Track 2 switches to costume2, while Track 3 switches to costume3.

This allows the scenery to change automatically when the player changes tracks.

Add Random Track Switching

The Space key can be used to switch tracks.

when [space] key pressed
next backdrop
switch backdrop to (pick random 1 to 3)

The important part is:

pick random 1 to 3

Scratch chooses a random number from 1 to 3, allowing the game to select one of the three tracks.

Add Different Car Designs

The same car sprite can have multiple costumes.

The number keys select different car designs.

if <key [1] pressed?> then
switch costume to [car_green_1]

if <key [2] pressed?> then
switch costume to [car_red_1]

if <key [3] pressed?> then
switch costume to [car_blue_1]

if <key [4] pressed?> then
switch costume to [car_black_1]

This allows the player to change the appearance of the car without creating separate sprites.

Test Everything

Now test the complete game.

Check that:

  1. ↑ moves the car forward
  2. ↓ moves the car backward
  3. ← and → turn the car
  4. Different track areas can change the speed
  5. The collider can stop the car
  6. All three tracks work
  7. The car starts in the correct position on each track
  8. The TREES costume changes with the track
  9. Space switches to a random track
  10. Keys 1–4 change the car's appearance

This is also a good time to fix any positioning or control problems you notice.

Try the Finished Game

Everything is now combined into the finished Scratch racing game.

🎮 CAR RACING THROUGH TRACKS!!!

Try all three tracks and experiment with the different car designs.

Main Game:

CAR RACING THROUGH TRACKS!!! on Scratch

Public Assets:

CAR RACING Public Assets on Scratch


What I Learned

This project helped me combine several Scratch concepts into one working game:

  1. Variables
  2. Keyboard input
  3. Conditions
  4. Collision detection
  5. Backdrop events
  6. Costumes
  7. Random numbers

One of the most useful things I learned is that a game does not have to be built all at once.

You can start with one mechanic, such as moving a car, and gradually add new systems around it.

Start small, make it work, and then keep adding features.

Future Improvements

There are many ways this racing game could be expanded.

Some ideas include:

  1. 🏆 Lap system — count completed laps
  2. ⏱️ Race timer — measure completion time
  3. 🥇 Best time — keep track of the fastest time
  4. 🤖 Opponent cars — add computer-controlled racers
  5. 🚦 Starting countdown — add a 3, 2, 1, GO! sequence
  6. 🔊 Sound effects — add engine and collision sounds
  7. 🛣️ More tracks — create additional racing layouts
  8. 🎚️ Difficulty levels — make different levels of challenge