# How to Make a Racing Game in Scratch, Step by Step
Author: Arpita Jain
Author URL: https://www.codeyoung.com/blog/author/arpita-jain
Published: 2026-11-25
Category: Coding For Kids & Teens
Category URL: https://www.codeyoung.com/blog/category/coding-for-kids-and-teens
Meta Title: How to Make a Racing Game in Scratch, Step by Step
Meta Description: Build a top-down racing game in Scratch 3: steering, speed and friction, grass that slows the car, a lap timer, and checkpoints so every lap counts once.
Tags: Coding For Kids, Game development, Scratch For Kids, Game Development For Kids, Scratch Programming, Coding Lessons
Tag URLs: Coding For Kids (https://www.codeyoung.com/blog/tag/coding-for-kids), Game development (https://www.codeyoung.com/blog/tag/game-development), Scratch For Kids (https://www.codeyoung.com/blog/tag/scratch-for-kids), Game Development For Kids (https://www.codeyoung.com/blog/tag/game-development-for-kids), Scratch Programming (https://www.codeyoung.com/blog/tag/scratch-programming), Coding Lessons (https://www.codeyoung.com/blog/tag/coding-lessons)
URL: https://www.codeyoung.com/blog/scratch-racing-game

A **racing game in Scratch** looks simple: a car, a track, a finish line. The version most children build first has a car that turns on the spot, drives at one speed, and counts nine laps every time it crosses the line. This tutorial builds the version that feels like driving. The car speeds up and coasts, slows down on the grass, steers like a real car, times every lap to a hundredth of a second, and only counts a lap that went all the way round.

For parents: this project is a real lesson in variables, multiplication as a rate, and state, which is the idea that a program has to remember what has already happened. Every step below ends with what should happen when your child clicks the green flag, so they can check their own work. It suits children of about 9 and up who have already built one Scratch game. If yours has not, start with our guide on [how to make a game on Scratch](https://www.codeyoung.com/blog/how-to-make-a-game-on-scratch).

## Key Takeaways

- Use a **speed variable** and multiply it by 0.9 every frame. With 0.6 added per frame while the up arrow is held, top speed settles at exactly 5.4 steps a frame.
- **Steer by speed**, with `turn right ((speed) * (0.8)) degrees`. The car cannot spin while parked, and its turning circle is the same size at every speed.
- **`touching color` is true on every frame the car overlaps the line**, so a plain lap counter adds 9 or 10 laps per crossing. A checkpoint variable fixes it.
- Two checkpoints in order stop shortcuts and stop players scoring laps by wiggling back and forth over the line.
- Time laps with the built-in `timer`, not a variable that goes up by 1 after `wait (1) seconds`. The wait version only counts whole seconds and runs slow.

## What you are building, and the numbers behind it

The game is **top-down**: you look at the track from above, like a map, and the car rotates as it turns. One sprite is the car. The track is painted on the backdrop, and the game reads the track by its colours. That is the whole trick of a Scratch racing game: `touching color ()?` lets one sprite react to grass, walls, the finish line and checkpoints without any of them being sprites.

Three facts about Scratch shape every number in this tutorial. The stage is 480 pixels wide and 360 tall. Scratch 3 runs scripts at **30 frames a second** in the editor and on the website, so a `forever` loop runs 30 times a second. And direction is measured clockwise from straight up: 0 is up, 90 is right, 180 is down and -90 is left.

## Step 1: paint the track on the backdrop

Click the **Stage**, open the **Backdrops** tab and paint a new backdrop. Use flat, solid colours only, because the car will recognise each part of the track by its colour:

- **Green** for grass. Fill the whole backdrop with it first.
- **Mid grey** for the road. Draw a thick loop: a rounded rectangle outline with the line width turned right up works well, or paint it with a wide brush. Make the road at least 70 pixels wide.
- **Red** for barriers. Add a few solid red blocks on the outside of the tightest corners.
- **White** for the finish line, a stripe about 10 pixels thick straight across the road.
- **Yellow** for checkpoint 1, a stripe across the road about a third of the way round.
- **Light blue** for checkpoint 2, about two thirds of the way round.

Decide which way the race goes, clockwise or anticlockwise, and put the checkpoints in that order after the finish line. Keep every corner gentle. Step 3 explains why: this car's tightest turn has a radius of about 72 pixels, so a hairpin tighter than that sends it onto the grass however well you drive.

![Top-down map of a Scratch racing track: a grey road loop on grass, a finish line across the road at the start, checkpoint 1 about a third of the way round and checkpoint 2 about two thirds round, barrier blocks on the outside of two corners, and arrows showing the race direction](https://prod.superblogcdn.com/site_cuid_clvc4016q001j13bhaleswmt1/images/scratch-racing-track-colour-zones-top-down-map-1795853672671-compressed.png)Every part of the track is a colour the car can sense. The two checkpoints sit a third and two thirds of the way round, in race order, so a lap only counts after both.

### Why the colours need to be clearly different

`touching color` is less exact than it looks. In the Scratch renderer's source code, the colour test keeps only the top five bits of red and green and the top four bits of blue. That means Scratch can tell apart only about 16,000 colours, not 16 million, and any shade close enough counts as a match. A very light grey such as #F8F8F0 counts as pure white, for example. Pick colours that are far apart, and never paint anything else on the backdrop in a shade near your finish-line white or checkpoint yellow.

When you choose the colour inside a `touching color` block later, click its swatch, pick the eyedropper and click the **middle** of the stripe on the stage. The edges of shapes are smoothed (anti-aliased) on the stage, and an edge pixel is a blend that will not match.

## Step 2: draw a car that faces right

Scratch's library cars, such as Convertible and Convertible 2, are drawn from the side, so they look wrong on a track seen from above. Paint your own. Click **Paint** under Choose a Sprite, draw a rectangle about twice as long as it is wide, and add a darker windscreen near the **right-hand** end. Drag the whole car so its middle sits on the small crosshair at the centre of the paint canvas, which is the point the car will rotate around.

The car must face **right** in the costume editor. A costume as drawn is what the sprite looks like at direction 90, so a car drawn facing up will drive sideways. Set its size in the sprite info so it is about 40 pixels long on the stage, and name the sprite Car.

Then build the start script on the car:

- `when green flag clicked`
- `set rotation style [all around]`
- `go to x: (0) y: (-130)` _(change this to a spot just behind your finish line)_
- `point in direction (90)`
- `set [speed] to (0)`

Make the variable first: Variables, **Make a Variable**, name it **speed**, choose **For this sprite only**. The rotation style block matters if anyone has ever clicked the left-right setting on this sprite. In the Scratch 3 source, left-right style always draws the sprite at direction 90 and only flips it, so a top-down car would slide round corners pointing sideways.

_Click the green flag:_ the car should jump to the start, facing along the road.

## Step 3: speed, friction and steering

This is the script that makes it feel like a car. Add a second script to the Car sprite. It starts on a broadcast so the countdown in step 6 can hold the car still; for now, add `broadcast (go)` at the end of the green flag script so it runs straight away.

- `when I receive [go]`
- `forever`
  - `if <key (up arrow) pressed?> then` `change [speed] by (0.6)`
  - `if <key (down arrow) pressed?> then` `change [speed] by (-0.3)`
  - `set [speed] to ((speed) * (0.9))`
  - `if <key (left arrow) pressed?> then` `turn left ((speed) * (0.8)) degrees`
  - `if <key (right arrow) pressed?> then` `turn right ((speed) * (0.8)) degrees`
  - `move (speed) steps`

Use `key () pressed?` from Sensing inside the loop, not the `when () key pressed` hat. The hat waits for the keyboard's own repeat delay, so the car would lurch, pause, then move.

### Why multiplying by 0.9 gives you a top speed

`set [speed] to ((speed) * (0.9))` is friction: every frame the car loses a tenth of its speed. While the up arrow is held it also gains 0.6 a frame. At first the gain wins and the car speeds up. As the speed grows, the tenth it loses grows too, until gain and loss are equal. That balance point is the top speed, and you can work it out: top speed = 0.6 × 0.9 ÷ (1 − 0.9) = **5.4 steps a frame**, or 162 pixels a second.

![Line chart of a Scratch car's speed per frame: it rises from 0 to 5.0 steps in 25 frames and levels off at 5.4 while the up arrow is held, falls back below 0.1 within 38 frames after the key is released, and drops to about 1 step a frame within 11 frames on grass](https://prod.superblogcdn.com/site_cuid_clvc4016q001j13bhaleswmt1/images/scratch-car-speed-friction-curve-chart-1795853679922-compressed.png)One multiplication gives three behaviours: acceleration that tapers off, coasting to a stop in about 1.3 seconds, and a hard slowdown on grass. All three come from multiplying speed by a number below 1.What happensFramesTime at 30 frames a secondFrom standing to 5.0 steps a frame, up arrow held250.8 secondsCoasting from 5.4 to below 0.1 after letting go381.3 secondsFull speed to about 1 step a frame on grass (step 4)110.4 seconds

Change the two numbers to change the car. A bigger gain, say 0.8, gives a faster car with a top speed of 7.2. A friction of 0.95 instead of 0.9 gives a slippery, icy car that takes much longer to stop. Reverse uses the same maths with a gain of -0.3, so the top reverse speed is -2.7, half the forward speed.

### Why steering uses speed, not a fixed number

A fixed turn, such as `turn right (5) degrees` while the arrow key is held, lets a parked car spin in place, which no car can do. Multiplying the turn by speed fixes three things at once. A stopped car does not turn at all. In reverse, speed is negative, so the car steers the opposite way, just as a real car does when backing up. And because the car turns 0.8 degrees for every step it moves, it always takes 450 steps to drive a full circle, whatever its speed. That makes the turning circle the same size at every speed, a radius of about **72 pixels**, which is the number to design your corners around.

_Click the green flag and drive:_ the car should pick up speed smoothly, coast to a stop when you let go, and refuse to turn while parked.

Copying a friction script takes a minute. Understanding why 0.6 and 0.9 settle at 5.4 is a first taste of algebra, and it is the point where a teacher makes the biggest difference. A free trial class with a Codeyoung teacher shows you where your child is and what they are ready for next, before you commit to anything.

[Book a Free Trial →](https://book-a-demo.codeyoung.com?utm_source=blog&utm_medium=codeyoung&utm_campaign=scratch-racing-game)

## Step 4: grass that slows you down, walls that push back

A popular page-one tutorial sends the car back to its starting position when it touches the grass. That punishes a small mistake far too hard. Slowing the car down is fairer, and it is one block. Add this straight after the friction line, before the steering:

- `if <touching color [green]?> then` `set [speed] to ((speed) * (0.7))`

On grass the car now loses 0.9 × 0.7 = 0.63 of its speed every frame, and the same maths as before gives a grass top speed of about **1 step a frame**, less than a fifth of the road speed. Cutting a corner across the grass is now slower than driving round it, which is the first line of defence against shortcuts.

### Barriers that the car cannot drive through

Walls need more care, because the car can get stuck in them. The obvious fix is `move ((0) - (speed)) steps` when touching the wall, which undoes the move but not the turn. If the driver steers into the wall, the car's nose rotates into the red, the move back does not rotate it out, and the car is stuck touching the wall every frame.

The reliable fix is to remember where the car was before it moved. Make three more variables for this sprite only: **last x**, **last y** and **last direction**. Put these three blocks at the very top of the forever loop:

- `set [last x] to (x position)`
- `set [last y] to (y position)`
- `set [last direction] to (direction)`

And this at the very bottom, after `move (speed) steps`:

- `if <touching color [red]?> then`
  - `go to x: (last x) y: (last y)`
  - `point in direction (last direction)`
  - `set [speed] to ((speed) * (-0.5))`

The car goes back to exactly where it was at the start of the frame, position and angle both, so it can never end a frame inside the wall. Multiplying speed by -0.5 bounces it backwards at half speed. The same save-and-restore pattern works for the walls of a maze, if your child has built one with our guide to [making a maze in Scratch](https://www.codeyoung.com/blog/how-to-make-a-maze-in-scratch-in-7-steps-cm9mm1od700ct14n5eix7ot9b).

_Click the green flag and drive into a barrier at full speed:_ the car should bounce off and never stick, however you steer.

## Step 5: count laps with a checkpoint, so each lap counts once

This is the step that page one gets wrong. A widely read car-racing tutorial describes the rule as one lap whenever the car touches the white lap line. Built literally, that is:

- `if <touching color [white]?> then` `change [laps] by (1)`

It does not count one lap. `touching color` is checked every frame, and it is true on **every** frame that any pixel of the car overlaps the line. A 40-pixel car crossing a 10-pixel line at the top speed of 5.4 steps a frame overlaps it for 50 pixels of travel, which is 9 or 10 frames. So one pass adds 9 or 10 laps. Slow down over the line and it adds more. Park on it and the counter climbs by 30 every second.

An obvious patch is `wait until <not <touching color [white]?>>` after the lap is added. That fixes the double count but leaves a bigger hole: a player can drive forward over the line, reverse back over it, drive forward again, and score a lap every few seconds without leaving the start. Cutting across the infield to the line works too.

### The checkpoint fix

Make five more variables, all for this sprite only: **laps**, **checkpoint**, **lap start**, **last lap** and **best lap**. Then add a third script to the car:

- `when I receive [go]`
- `set [laps] to (0)`
- `set [checkpoint] to (0)`
- `set [best lap] to (0)`
- `set [lap start] to (timer)`
- `forever`
  - `if <<touching color [yellow]?> and <(checkpoint) = (0)>> then` `set [checkpoint] to (1)`
  - `if <<touching color [light blue]?> and <(checkpoint) = (1)>> then` `set [checkpoint] to (2)`
  - `if <<touching color [white]?> and <(checkpoint) = (2)>> then`
    - `set [checkpoint] to (0)`
    - `change [laps] by (1)`
    - `set [last lap] to ((round ((((timer) - (lap start)) * (100)))) / (100))`
    - `set [lap start] to (timer)`
    - `if <<(best lap) = (0)> or <(last lap) < (best lap)>> then` `set [best lap] to (last lap)`

The **checkpoint** variable is the game's memory of how far round the car has been. It can only go 0, then 1 at the yellow stripe, then 2 at the light blue one, in that order. The white line only counts when it is 2, and counting a lap sets it straight back to 0. That one reset is what stops the 9-lap bug: on the next frame the car is still on the line, but checkpoint is 0, so nothing happens.

![Cycle diagram of a Scratch lap counter's checkpoint variable: it starts at 0, becomes 1 when the car touches checkpoint 1, becomes 2 when it touches checkpoint 2, and only then does touching the finish line add one lap and reset it to 0; touching a stripe out of order does nothing](https://prod.superblogcdn.com/site_cuid_clvc4016q001j13bhaleswmt1/images/scratch-lap-checkpoint-state-cycle-diagram-1795853687474-compressed.png)Three values and one reset. Touching a stripe out of order changes nothing, so a lap can only be scored by passing checkpoint 1, then checkpoint 2, then the line.

It also beats the cheats. Wiggling over the line scores nothing, because checkpoint is 0. Cutting across the grass misses a checkpoint. Driving the whole track backwards meets the light blue stripe first, while checkpoint is still 0, so it is ignored; a player going the wrong way has to drive two full laps to score one. Notice also that the car starts just behind the line with checkpoint at 0, so crossing the line at the start of the race does not count as a lap, which is what you want.

With one checkpoint instead of two, a player could drive backwards to it and then forwards to the line, half a lap each way. That is no shorter than racing, so it is not a real shortcut, but two checkpoints make the rule simple to explain: go all the way round, the right way.

_Click the green flag and drive one lap:_ laps should go from 0 to 1 exactly once when you cross the line. Then try wiggling over the line and cutting across the grass. Laps should not change.

If your child wants a scoreboard that looks better than a variable monitor, our guide to [building a score counter in Scratch](https://www.codeyoung.com/blog/scratch-score-counter) covers showing a number on the stage and explains when a variable should be for all sprites or for this sprite only.

## Step 6: a countdown and a lap timer that does not drift

The lap script above already times laps with Scratch's built-in `timer`, from the Sensing category. It reports the seconds since the project started, to thousandths of a second. Scratch's source resets it every time the green flag is clicked, and `reset timer` sets it back to 0 whenever you like.

Some tutorials build their own clock instead: a variable that goes up by 1 inside `forever` after `wait (1) seconds`. Avoid it here for two reasons. It only counts whole seconds, so two laps of 23.4 and 23.9 seconds would both read 23. And it can only run slow, never fast: in the Scratch 3 source, a wait finishes on the first frame after the second is up, and the loop then has to come round again before the next wait starts. Every pass takes a little more than a second, and the error builds up over a race. Our step-by-step guide on [how to make a timer in Scratch](https://www.codeyoung.com/blog/how-to-make-a-timer-in-scratch-step-by-step-timer-tutorial-for-students) compares the two approaches in detail.

Now add a countdown so nobody can start early. Change the end of the car's green flag script to:

- `say [3] for (1) seconds`
- `say [2] for (1) seconds`
- `say [1] for (1) seconds`
- `say [Go] for (0.5) seconds`
- `reset timer`
- `broadcast (go)`

The `reset timer` matters. The timer started at the green flag, so without it the first lap would include the three-second countdown. The driving and lap scripts both start on `when I receive [go]`, so the car cannot move until the countdown ends. Broadcasts are how one script starts others at exactly the right moment; our guide to [Scratch broadcast blocks](https://www.codeyoung.com/blog/scratch-broadcast-blocks) explains them properly.

_Click the green flag:_ the car should count down, refuse to move until Go, and show a last lap time such as 21.37 after the first lap.

## Step 7: finish the race after three laps

Inside the lap block, after the best-lap check, add:

- `if <(laps) = (3)> then`
  - `set [speed] to (0)`
  - `broadcast (finished)`
  - `say (join [Finished in ] ((round ((timer) * (100))) / (100)))`
  - `stop [other scripts in sprite]`

`stop [other scripts in sprite]` stops the driving loop, so the car halts on the line instead of coasting on. Because the timer was reset at Go, `timer` at this moment is the total race time. Any other sprite, such as a big Finished banner or a sound, can react with `when I receive [finished]`.

Here is the complete driving script with steps 3 and 4 in place:

- `when I receive [go]`
- `forever`
  - `set [last x] to (x position)`
  - `set [last y] to (y position)`
  - `set [last direction] to (direction)`
  - `if <key (up arrow) pressed?> then` `change [speed] by (0.6)`
  - `if <key (down arrow) pressed?> then` `change [speed] by (-0.3)`
  - `set [speed] to ((speed) * (0.9))`
  - `if <touching color [green]?> then` `set [speed] to ((speed) * (0.7))`
  - `if <key (left arrow) pressed?> then` `turn left ((speed) * (0.8)) degrees`
  - `if <key (right arrow) pressed?> then` `turn right ((speed) * (0.8)) degrees`
  - `move (speed) steps`
  - `if <touching color [red]?> then` `go to x: (last x) y: (last y)`, `point in direction (last direction)`, `set [speed] to ((speed) * (-0.5))`

## Testing checklist: six bugs and their fixes

SymptomCauseFixCar drives sidewaysCostume drawn facing upRedraw it facing right; direction 90 shows the costume as drawnCar points the same way round cornersRotation style is left-right or don't rotate`set rotation style [all around]`9 or 10 laps per crossingPlain `if touching color` lap counterCheckpoint variable, reset to 0 when a lap countsGrass or wall check never firesColour picked from a blended edge pixelEyedropper the middle of the shapeCar sticks inside a barrierMove undone but turn not undoneSave and restore x, y and directionFirst lap time 3 seconds too longCountdown counted in the timer`reset timer` just before `broadcast (go)`

## Where to take the racing game next

- **Two players.** Right-click the car, choose duplicate, and change the keys to W, A, S and D. Because every variable was made for this sprite only, each car gets its own speed, laps and checkpoint. Paint the second car a colour that is not green, red, white, yellow or light blue: `touching color` checks other sprites as well as the backdrop, so a white car would count as a finish line for the other player.
- **A best lap that survives a reload.** Best lap resets every race. Keeping a record between sessions needs a cloud variable, and our guide to [saving a high score in Scratch](https://www.codeyoung.com/blog/scratch-save-high-score) explains the rules, including which accounts can use them.
- **Drifting.** Move the car's rotation centre forward, between the front wheels, in the costume editor. The car then pivots near its nose and the back swings out on corners, a trick suggested on the Scratch forums that costs no extra code.
- **A computer opponent.** The angle maths for chasing a target is the same as in our [Scratch Pong tutorial](https://www.codeyoung.com/blog/scratch-pong-game), where a computer paddle moves toward the ball at a capped speed so it can lose.

## Conclusion

A good racing game in Scratch is a speed variable multiplied by 0.9 every frame, steering tied to that speed, and a track painted in flat colours the car can sense. The part that separates it from a broken one is the lap counter. `touching color` stays true for every frame the car is on the line, so the game has to remember where the car has been, and a checkpoint variable that only moves 0, 1, 2 in order does exactly that. It is also the clearest introduction to program state a child will meet in Scratch.

If your child enjoyed building this, Codeyoung's [Scratch coding classes](https://www.codeyoung.com/coding/scratch-coding-classes-for-kids?utm_source=blog&utm_medium=codeyoung&utm_campaign=scratch-racing-game) take projects like this further with a teacher alongside, so a car stuck in a wall becomes a lesson in debugging instead of a reason to give up.

Codeyoung runs 1:1 live online classes for children aged 6 to 17, with a teacher who adapts the pace to your child rather than a fixed syllabus. The first class is free, so you can see how they respond before deciding.

[Book a Free Trial](https://book-a-demo.codeyoung.com?utm_source=blog&utm_medium=codeyoung&utm_campaign=scratch-racing-game)

Sources checked 28 November 2026: the Scratch Foundation's scratch-vm source for [move steps and turn](https://github.com/scratchfoundation/scratch-vm/blob/develop/src/blocks/scratch3_motion.js), touching color and the timer (scratch3\_sensing.js), the project clock and its reset on the green flag (clock.js and runtime.js), wait (scratch3\_control.js) and rotation styles (rendered-target.js); the colour comparison and touching candidates in scratch-render's RenderWebGL.js; the 30 frames a second compatibility setting in scratch-gui's vm-manager-hoc.jsx; the Convertible sprites in scratch-gui's sprite library; the Scratch Wiki page [Touching Color ()?](https://en.scratch-wiki.info/wiki/Touching_Color_()%3F_(block)); and the Scratch forum thread on drifting cars. Speeds, frame counts and the turning circle are calculated from those formulas at 30 frames a second, not timed in a live editor; a slow computer that drops frames will run the game more slowly.
## FAQs
Q: How do you make a racing game in Scratch?
A: Paint a track on the backdrop in flat colours: grey road, green grass, a white finish line. Draw a small top-down car that faces right. In a forever loop, change a speed variable with the arrow keys, multiply it by 0.9 for friction, turn with the left and right keys and move speed steps. Count laps with the finish line plus a checkpoint.

Q: Why does my Scratch racing game count lots of laps at once?
A: Touching color stays true for every frame the car overlaps the finish line. A 40-pixel car crossing a 10-pixel line at 5.4 steps a frame touches it for 9 or 10 frames, so a plain if block adds 9 or 10 laps. Add a checkpoint variable that must be set before the line counts, and reset it when the lap is added.

Q: How do you stop players cheating by taking shortcuts in a Scratch racing game?
A: Paint two checkpoint stripes across the road, one about a third of the way round and one about two thirds. Use a checkpoint variable that goes 0, 1, 2 only in that order, and only add a lap at the finish line when it is 2. Cutting across the grass or wiggling over the line then scores nothing.

Q: How do you make a car steer realistically in Scratch?
A: Turn by an amount tied to speed, such as turn right speed times 0.8 degrees, instead of a fixed 5 degrees. The car cannot spin on the spot, it steers the other way in reverse like a real car, and its turning circle stays the same size, with a radius of about 72 pixels, at every speed.

Q: How do you make a lap timer in Scratch?
A: Use the built-in timer reporter from Sensing. Store the timer in a variable called lap start when a lap begins, and when the car crosses the line set last lap to timer minus lap start. Round it with round of value times 100, divided by 100, to show hundredths of a second.

Q: Why does my car go through walls in my Scratch racing game?
A: Either the wall colour is not an exact match, or the car turned into the wall and the move back did not undo the turn. Save x, y and direction at the start of every frame, and if the car touches the wall colour, go back to all three saved values and reverse the speed.




---
This blog is powered by Superblog. Visit https://superblog.ai to know more.
---

