๐Ÿ˜ธ Simple Interactions | Betabox

๐Ÿ˜ธ Simple Interactions

Often times, we’ll want to be able to write some code that happens when two sprites touch each other. This could be things like:

  • A laser beam touches an enemy in a game
  • A character touches another character while walking across the screen
  • Any other ideas?

In Scratch, this is really easy!

For example, let’s say we want a character to say “Excuse me!” when she walks past another character, like this:

We can have the first character walk across the screen as usual, but use anย if/else block to check if she’s touching the other character.

This is a really simple example, so let’s check out another one — a game where a hedgehog has to collect cheese puffs. Every time the hedgehog touches a bowl of cheese puffs, one point is added, and the cheese puffs disappear.

This is a little more complex to code, but you can see the “if touching Hedgehog” code, very similar to the first example.