GoalWrite an algorithm and a program in which one sprite follows another sprite.
New words
sprite · a character or object in a Scratch project; each sprite has its own codeinteract · to affect each other, for example when one sprite follows or talks to anotherrandom position · a place on the stage chosen by chancepoint towards · a block that turns a sprite to face another sprite or the mouse pointer
Explanation
A Scratch project can have many sprites, and each sprite has its own scripts. When two sprites affect each other, we say that they interact. In a following game, one sprite is the leader and wanders about. The other sprite is the follower. It turns to face the leader and then glides to it, again and again. The two sprites need two different algorithms, and both start when the green flag is clicked. The follower’s blocks have a drop-down list. Once the leader is in the project, its name appears in that list.
Worked examples
The butterfly repeats its glide 6 times, and each glide takes 3 seconds. So the leader’s script takes 6 × 3 = 18 seconds. After that the script ends and the butterfly stays still.
The bee repeats 12 times, and each glide takes 2 seconds. So the follower’s script takes 12 × 2 = 24 seconds. For the last 6 seconds the butterfly is not moving, so the bee reaches it and stays on it.
A shorter glide makes a quicker follower. If the bee glides for 1 second instead of 2, the same 12 repeats take only 12 × 1 = 12 seconds.
Class activity
Leader and follower (with a friend, indoors or in a safe play area). The leader walks to any spot, stops, and counts to three. The follower stops, turns to face the leader (point towards) and walks to the leader’s spot (glide). Do 6 rounds. Then write the follower’s algorithm as numbered steps, using the words ‘point towards’, ‘glide to’ and ‘repeat’. If you have a computer or tablet, build both scripts in Scratch with two sprites of your choice and run them.
Practice
1
A kitten follows a ball of wool. Which block makes the kitten turn to face the wool? How many times does it turn to face it?
The ‘point towards (Wool)’ block. It is inside repeat (8), so the kitten turns to face the wool 8 times. The glide block only moves the kitten.
2
A ball script repeats 5 times with a 4-second glide. A dog script repeats 8 times with a 3-second glide. Which script is longer, and by how many seconds?
The ball takes 5 × 4 = 20 seconds. The dog takes 8 × 3 = 24 seconds. The dog’s script is 4 seconds longer.
3
A pupil leaves out ‘point towards’ and keeps only ‘glide to’. Will the follower still reach the leader? What is different?
Yes, it still arrives, because the glide block moves it to the leader. But it never turns to face the leader, so it does not look like it is following.
4
Put these blocks in the right order for a follower script: glide (2) secs to (Hen); when the green flag is clicked; repeat (10); point towards (Hen).
1 when the green flag is clicked, 2 repeat (10), 3 point towards (Hen), 4 glide (2) secs to (Hen). The last two blocks are inside the repeat.