How I Made a Car Racing Game in Scratch — A Beginner Game Project
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.
CAR RACING THROUGH TRACKS!!! on Scratch
Prefer watching instead of reading? I also made a complete video tutorial showing how the project was created.
▶ Watch the Full Tutorial🎮 What Is the Game About?
The main idea is straightforward: drive a car through different racing tracks using the keyboard.
The project contains three different tracks, and the car has different starting positions depending on which track is selected.
The game also includes a basic speed system. The car normally moves at a higher speed, but certain areas can slow it down. A collider system is also used to detect specific areas of the track.
There is also a customization feature that lets the player change the car's appearance using the number keys.
Controls
| Key | Action |
|---|---|
| ↑ Up Arrow | Move forward |
| ↓ Down Arrow | Move backward |
| ← Left Arrow | Turn left |
| → Right Arrow | Turn right |
| Space | Switch to a random track |
| 1–4 | Change the car appearance |
🧩 Setting Up the Project
The project is made using a few main elements:
- car — the player-controlled vehicle
- collider — used for collision detection
- TREES — contains the tree artwork for the different tracks
- Three backdrops — track 1, track 2, and track 3
Instead of creating completely separate games for every track, I used the same car and changed its position, direction, and environment when the backdrop changes.
The TREES sprite has different costumes for the different tracks. When the backdrop changes, the sprite switches to the appropriate costume.
when backdrop switches to [track 1] switch costume to [costume1]
Similar scripts are used for the other tracks. This keeps the project organized because the same sprite can provide different scenery for each track.
🚗 Programming the Car
The car is the most important sprite in the project because it controls the actual gameplay.
When the game starts, the car is placed at its starting position and given an initial direction. The project uses a variable called speed to control how quickly the car moves.
when green flag clicked go to x: -179 y: -88 point in direction 0 set [speed] to 2
The speed variable is useful because the car doesn't always have to move at the same speed. Other scripts can change this value during gameplay.
⬆️ Moving Forward
The up arrow is used to drive forward.
if <key [up arrow] pressed?> then
move (speed) steps
Instead of putting a fixed number directly into the movement block, the project uses the speed variable.
For example, if the speed is 2, the car moves two steps at a time. If the game changes the speed to 0.5, the car moves much more slowly.
⬇️ Reversing
The down arrow allows the player to move backward.
if <key [down arrow] pressed?> then
move (-1) steps
Using a negative value makes the car move in the opposite direction.
↩️ Turning the Car
The left and right arrow keys 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
The car checks these controls continuously inside a forever loop. This allows the player to drive and turn during the same game.
🧠 The Main Car Logic
The main car script combines the movement and turning controls:
when green flag clicked
go to starting position
point in starting direction
set speed to 2
forever
if up arrow pressed
move speed steps
if down arrow pressed
move -1 steps
if right arrow pressed
turn 5 degrees
if left arrow pressed
turn -5 degrees
This is basically the core of the game. Once this system works, the other systems can be built around it.
⚡ Creating a Speed System
The speed variable isn't only used for normal movement. The game can change the speed depending on what the car is touching.
if <touching color ... or touching color ...> then
set speed to 0.5
else
set speed to 2
This creates a simple road or terrain detection system.
When the car is on the normal driving area, its speed stays at 2. When it touches one of the specified colors, the speed changes to 0.5.
This gives the track a little more gameplay instead of allowing the car to move at exactly the same speed everywhere.
💥 Adding Collision Detection
Another part of the game uses the collider sprite.
forever
if <touching [collider]?> then
set speed to 0
When the car touches the collider, its speed is set to zero. This provides a simple way to make certain areas of the track behave like obstacles or boundaries.
🛣️ Adding Multiple Tracks
One of the main features of the project is that it has three different tracks.
- Track 1
- Track 2
- Track 3
Each track has its own layout. Because the layouts are different, the car needs a different starting position and direction for each one.
For example, the first track uses:
when backdrop switches to [track 1] go to x: -179 y: -88 point in direction 0
Another track uses a different starting position:
when backdrop switches to [track 2] go to x: 179 y: 88 point in direction 180
The third track also has its own starting position and direction.
This is important because simply changing the backdrop isn't enough. If the car stayed in the same position after every track change, it could appear somewhere completely wrong.
🌳 Changing the Track Environment
The same idea is used with the TREES sprite. When the backdrop changes, the sprite changes its costume.
when backdrop switches to [track 2] switch costume to [costume2]
Another script can switch to the appropriate costume for track 3.
This allows the scenery to match the current track. Instead of creating a separate tree sprite for every track, multiple costumes are stored inside the same sprite.
🔀 Randomly Switching Tracks
I also added a quick way to change tracks. When the player presses the Space key, the game selects a random track.
when [space] key pressed switch backdrop to (pick random 1 to 3)
The important part is the pick random 1 to 3 block. Scratch chooses a random number between 1 and 3, which corresponds to one of the three tracks.
So pressing Space can take the player to a randomly selected track.
🎨 Adding Different Car Designs
The game also includes different car appearances. Instead of creating four separate car sprites, I used multiple costumes for the same car sprite.
The number keys select the different versions:
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 means the player can change the appearance of the car while staying in the same game.
It is also a good example of why Scratch costumes are useful: one sprite can have many visual variations.
🏁 Making Everything Work Together
At this point, several different systems are working together:
- Keyboard controls tell the car how to move.
- The speed variable controls how quickly it moves.
- Color detection changes the speed depending on the area of the track.
- The collider can stop the car when it reaches certain areas.
- Backdrop switching changes the track.
- Track-specific scripts place the car at the correct starting position.
- Costumes change the car and scenery.
- Random selection lets the player choose a random track.
None of these systems is particularly complicated by itself. The interesting part is combining them into one working game.
🖥️ The Finished Project
The final project combines the track artwork, car, trees, and gameplay scripts into one Scratch game.
🧠 What I Learned From Building It
This project gave me a chance to use several Scratch concepts together.
Variables
The speed variable controls the car's movement and can be changed during gameplay.
Keyboard Input
The project uses keyboard events to control movement and customization.
Conditions
if blocks allow the game to react to the player's actions and the environment.
Collision Detection
touching blocks can detect when the car reaches particular objects or areas.
Backdrop Events
when backdrop switches to allows sprites to react whenever the player changes tracks.
Costumes
Multiple costumes make it possible to change the appearance of the car and scenery without creating many separate sprites.
Random Numbers
pick random 1 to 3 makes the track selection unpredictable.
🐛 Things to Think About When Building Your Own Version
A multi-track Scratch game needs a little more setup than a single-track project.
For every new track, you need to think about:
- Where should the car start?
- Which direction should it face?
- Which scenery costume should appear?
- Which areas should slow the car down?
- Where should collision detection happen?
If you add another track later, you would need to add the corresponding backdrop and update the scripts that currently work with the existing tracks.
Planning these things before adding more content can save a lot of debugging later.
🧰 Public Assets
I also created a separate Scratch project for the public assets used with the racing project.
This gives the project a separate place for resources and makes it easier to reference the assets without mixing everything into the main game's project structure.
Open the CAR RACING Public Assets project on Scratch
🚀 What Could Be Added Next?
The current game can also be expanded with more racing mechanics.
- 🏆 Lap System — Add checkpoints and count completed laps.
- ⏱️ Race Timer — Measure how quickly a track is completed.
- 🥇 Best Time — Save the player's fastest time.
- 🤖 Opponent Cars — Add computer-controlled racers.
- 🚦 Starting Countdown — Add a 3, 2, 1, GO! sequence.
- 🔊 Sound Effects — Add engine, collision, and background sounds.
- 🏁 More Tracks — Create additional layouts and challenges.
- 🎚️ Difficulty Levels — Create different levels of challenge.
🎮 Try It Yourself
If you want to see how all of these systems work together, try the finished project on Scratch.
💡 Final Thoughts
This project started with a simple idea: make a car that can race around a Scratch track.
As I worked on it, I added multiple tracks, keyboard controls, speed changes, collision detection, different car costumes, and random track selection.
One of the most useful things about Scratch is that you don't need to build everything at once. You can start with one working mechanic, such as moving a car, and gradually add new systems around it.
That's what makes projects like this useful for learning game development: start small, make it work, and then keep adding features.
More tracks, opponents, checkpoints, timers, or something completely different could turn this small project into a much larger racing game.
🔗 Project Links
Scratch is a project of the Scratch Foundation. This article documents an independently created Scratch project.
Comments
Post a Comment