From the course: Learning Scratch

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detect collisions

Detect collisions - Scratch Tutorial

From the course: Learning Scratch

Start my 1-month free trial

Detect collisions

- [Voiceover] So right now, the rocks move and you can control the cat, but there's no connection between the rocks and the cat. So what we're going to do is add some code to detect collisions between the rocks and the cat, and stop the game when those collisions happen. So, to do that, I'm going to start in the rock so I have the rock sprite selected, and I'm in the scripts panel and I'm looking at the rock scripts. So what we want to do is check to see in our forever loop if the rock is touching the cat. So, we'll go over to control and find if/then and just drag that out underneath the if/why position block and inside the forever loop and then we'll head over to sensing. And we want to see if it's touching another object. So I'm going to drag out this touching 1 and then change this in the dropdown to sprite 1. So, if it's touching sprite 1, then what we want to do is bring the rock to the front. We want the rock to be in front of the cat in that case, and then we want to basically…

Contents