Scratch exercise 70

Vicinity - using the "distance to" script block

You can create a sprite which will react to another sprite depending on how close they are to each other.

In this exercise you will make a chasing object follow the Cat whenever the Cat gets close, but which will move back to its starting position when the Cat moves away again.


Complete these steps ..


1. Create a new game. Either open Scratch or if it is already open choose "File>New" ..


Now re-name sprite1 "Cat".

2. Click the "Paint new sprite" button under the stage paint new sprite icon and draw a chasing object.

It could be a dog or a bee. In this exercise we have just created a simple red ball ..

When you are done click "OK" and rename the sprite. We have called our ball "Chasing object".



3. Add these scripts to the Cat sprite ..



4. Add these scripts to the chasing object ..

Notice how the chasing object will follow or "chase", the Cat when the Cat is closer that 200 pixels from it.

Notice how the chasing object will retreat back to its original position when the Cat is greater that 200 pixels from it.

5. Go to "File > Save as" and save your game. Name the game "Distance to".



6. Press "B" and then use the arrow keys to test your game.


7. Can you develop these scripts into your own game.