Learning Goals 3 min
By the end of this lesson you will be able to:
- Find touching (Sprite v) ? in the Sensing palette and explain that it asks "am I, this sprite, touching that sprite right now?".
- Drop the reporter into a if <> then so one sprite reacts the instant it bumps another — the heart of every catch-the-thing or avoid-the-thing game.
- Build a tiny two-sprite project where the cat says
Ouch!when it bumps a ball — and explain why the script lives on the cat, not on the ball.
Warm-Up — two sprites, two stories 7 min
In SCR-L02-02 you put two sprites in one project for the first time — the cat and a ball. Each one had its own script. Each one ran independently. They lived in the same Stage but didn't notice each other.
when flag clicked
forever
move (5) steps
if <touching [edge v] ?> then
turn cw (180) degrees
end
end
Click the flag. The cat bounces. The ball bounces. They cross each other on the Stage and… nothing happens. They walk straight through each other like ghosts.
Reveal the issue
Each sprite only knows about itself and the Stage edges. Neither one has ever asked "am I touching the other sprite?". Today's lesson is the block that asks exactly that.
Today the cat learns to notice the ball. Once it can notice, it can react. Once it can react, you have a game.
New Concept — touching (another sprite)? 15 min
In L02-06 you met touching [edge v]? — the boolean reporter that asks "am I touching the edge of the Stage?". It has a tiny dropdown next to "edge". Open it.
<touching [edge v] ?>
What's in the dropdown
The dropdown shows three kinds of things:
- edge — the edge of the Stage (what you used last week).
- mouse-pointer — the position of the mouse cursor on the Stage.
- Every other sprite in your project — by name. So if your project has a "Ball" and a "Goal", you'll see those two extra options.
Pick a sprite name and the reporter now asks "am I, this sprite, touching that named sprite, right now?". True if their costumes overlap on the Stage. False otherwise.
<touching (Ball v) ?>
"This sprite" vs "that sprite" — the perspective rule
The reporter is always written from the asking sprite's point of view. If the script is on the cat, then touching (Ball v) ? means "am I, the cat, touching the ball?". If you drag the same script onto the ball, the same block now means "am I, the ball, touching the cat?" — flip the perspective. The answer is the same, but the question reads differently.
This is why where you put the script matters. In a cat-touches-ball game, the script lives on the cat (or on the ball — either works for two sprites). In a ball-touches-goal game, the script lives on either ball or goal, but the dropdown picks the other sprite. Get the perspective right and the rest writes itself.
Plug it into if-then
The reporter on its own is just a question. To do something about the answer, drop it into the diamond of an if-then, inside a forever loop — the same pattern from L02-06.
when flag clicked
forever
if <touching (Ball v) ?> then
say [Ouch!] for (1) seconds
end
end
Worked Example — the cat that says "Ouch!" 14 min
A two-sprite project, eight steps. The cat-pet walks. A ball-treat bounces back and forth. The pet reacts when they touch.
Step 1 — Start with two sprites
New project. The cat is already there. From the sprite picker (bottom-right corner, blue cat-with-+ icon), pick the Ball sprite (or any small object). You now have two sprites in the Sprite list.
Step 2 — Position them apart
Drag the cat to the left side of the Stage, around x: −180. Drag the ball to the right side, around x: 180. Make sure they're roughly at the same y (height) so they'll meet in the middle when they walk.
Step 3 — Give the cat its walking script
Click the cat in the Sprite list. Build:
when flag clicked
forever
move (3) steps
if <touching [edge v] ?> then
turn cw (180) degrees
end
end
Step 4 — Give the ball a matching walker
Click the ball in the Sprite list. Build the same shape but slower:
when flag clicked
point in direction (-90)
forever
move (2) steps
if <touching [edge v] ?> then
turn cw (180) degrees
end
end
Step 5 — Click the flag and watch them pass through each other
The cat and ball walk toward each other, meet in the middle, and walk straight past as if the other one wasn't there. Step 6 fixes that.
Step 6 — Add the touching question to the cat
Click the cat in the Sprite list. Add a second script (not snapped to the walker — separate hat):
when flag clicked
forever
if <touching (Ball v) ?> then
say [Ouch!] for (1) seconds
end
end
Step 7 — Click the flag again
The cat walks. The ball walks. They meet in the middle. The instant they touch, the cat says "Ouch!" in a speech bubble for one second. They keep walking, the bubble disappears, they hit edges and turn around, they come back, touch again, "Ouch!" again. It looks like they're noticing each other.
Step 8 — Save it
Project name: L2-12-Cat-Meets-Ball. File → Save to your computer.
What you just built: the smallest possible collision detector. Every catch-the-falling-apple, dodge-the-asteroid, defeat-the-boss game uses some version of this — a sprite that watches for contact with another sprite and reacts.
Try It Yourself — three contact drills 15 min
Goal: Add a second sprite (a star, a heart, anything small) to a fresh project. Make the cat hide the instant it touches the star. (When the cat moves away, it can stay hidden — that's fine for this drill.)
when flag clicked
show
forever
if <touching (Star v) ?> then
hide
end
end
Think: If the cat never moves, it never touches the star — drag the cat manually on the Stage to test, or add a go to (mouse-pointer v) so the cat follows your mouse.
Goal: Two sprites — a fish and a shark. The fish swims forever (using the warmup pattern). When the fish touches the shark, the fish says Oh no! for half a second and turns around to swim the other way.
when flag clicked
forever
move (4) steps
if <touching [edge v] ?> then
turn cw (180) degrees
end
if <touching (Shark v) ?> then
say [Oh no!] for (0.5) seconds
turn cw (180) degrees
end
end
Think: The shark doesn't need a script at all (unless you want it to move too). The whole game lives on the fish, because the fish is the one that needs to react.
Goal: A keyboard-controlled catch game. A goalie sprite moves left and right with the arrow keys. A ball sprite drops from the top of the Stage to the bottom forever. When the ball touches the goalie, the ball jumps back to the top to start again.
when flag clicked
forever
go to x: ((pick random (-200) to (200))) y: (160)
repeat until <touching (Goalie v) ?>
change y by (-5)
if <(y position) < (-170)> then
change y by (340)
end
end
end
Think: This is your first taste of a game loop with an end condition — "fall until touching goalie". The condition is a boolean, just like the if-then's diamond — same shape, same place.
Mini-Challenge — the wrong sprite gets the blame 5 min
"Priya's confused cat"
Priya has a project with two sprites: a cat and a fish. She wants the fish to say "Glub!" when the cat bumps it. She writes this script and attaches it to the cat:
when flag clicked
forever
if <touching (Fish v) ?> then
say [Glub!] for (1) seconds
end
end
Click the flag in your head. Drag the cat onto the fish. Who actually says "Glub!", and what should Priya change?
Reveal one valid solution
The cat says "Glub!" — because the say block lives on whichever sprite the script is attached to. The touching-question itself is correct (the cat is checking "am I touching the fish?"), but the reaction happens on the wrong sprite.
Two equally good fixes:
Fix A: Move the whole script onto the fish and flip the dropdown to touching (Cat v) ?. Same logic, mirrored perspective.
when flag clicked
forever
if <touching (Cat v) ?> then
say [Glub!] for (1) seconds
end
end
Fix B (uses next-cluster ideas): Keep the script on the cat, but have it broadcast (bumped v) instead of saying. Then put a when I receive (bumped v) + say [Glub!] for (1) seconds on the fish. You'll meet this pattern in cluster D (L02-20 onward).
The deeper lesson: which sprite the script lives on decides which sprite acts. Touching reports the same boolean from either side, but only the sprite holding the script can do something about it.
Recap 3 min
You learned the second flavour of the touching reporter — touching (Sprite v) ?. Pick another sprite from the dropdown and the block asks "am I, this sprite, touching that one, right now?". Drop it into an if-then inside a forever loop and you have collision detection — the foundation of every two-sprite game. The script lives on the sprite that needs to react, and the dropdown names the sprite to watch for.
- Touching (Sprite v) ?
- A Sensing boolean reporter that returns true when this sprite's costume overlaps the named sprite's costume on the Stage. Same shape (hexagonal) as touching-edge.
- Collision detection
- The general pattern of asking "are these two things touching?" so a script can react. Built from touching + if-then + forever.
- Perspective
- A touching script always asks the question from the host sprite's point of view. Moving the same script between sprites flips which one is asking.
- Sprite list
- The panel in the bottom-right of the Scratch editor that lists every sprite in the project by name. Those exact names show up in the touching dropdown.
- Independent scripts
- The cat and the ball each have their own scripts running at the same time. Forever loops on different sprites don't interfere with each other — they all run in parallel.
Homework 2 min
The Tag Game. Build a tiny two-sprite tag game.
- Two sprites: a runner (the cat) and a tagger (any other sprite — fish, ball, dinosaur, you choose).
- The runner follows the mouse pointer forever — forever + go to (mouse-pointer v). Players drive the runner with their mouse.
- The tagger walks slowly back and forth across the Stage forever, bouncing off the edges (the warmup pattern, slower).
- On the runner, add a second script: when the runner touches the tagger, the runner says
Tag!for one second and the project ends — stop [all v].
Save as HW-L2-12-Tag.sb3. The mouse-driven cat tries to dodge the bouncing tagger for as long as it can.
Bring back next class:
- The
.sb3. - Your highest "score" — how many seconds you survived before getting tagged. Use the Stage timer if you want: timer reports seconds since the flag was clicked. Print it with say (timer) at game-end.
Heads up for next class: SCR-L02-13 adds touching color (#000000) ? — the same idea, but asking about colours instead of sprites. Maze games are built from this.