# Video Sensing extension

By using the Video Sensing extension, your Scratch project can react to the user's motion. Watch Mark demonstrate here.

In this step, you’ll use the Video Sensing extension so that users can interact with your Scratch projects. The Video Sensing extension allows you to overlay the video from your webcam onto the Stage, so that users can “reach towards” and interact with sprites.

### Adding the Video Sensing extension blocks

When you add the Video Sensing extension blocks, the video stream from your webcam will appear on the Stage with sprites “on top” of your video. If you are using the online version, you may need to allow Scratch access to use your camera.

### Video transparency

When the video stream appears on the Stage, the video stream will look partially see-through. This is because the transparency of the video stream is set to 50 percent by default. When the video transparency is set to 0 the video stream has no transparency — you cannot see the backdrop on the stage. When you set the transparency to 100 you can see the backdrop on the Stage and no image from your video stream.

To change the transparency of the video, you need to use the set video transparency to () block.

The image below shows how the Stage area will appear with the transparency set at: 20, 40, 60 and 80.

### On and off

Although by default the video starts on, you may want to turn it off, and later turn it back on. For example, you may not want the video on while you present a welcome screen, or a final score. To do this, use the turn video () block.

### Motion

Scratch will detect motion on the video. You can use this to start some code running using the when video motion > () block. If this code is on a sprite, Scratch will wait for motion on the video in the area hidden by the sprite, while if this code is on the Stage, Scratch will look for motion across the whole video.

To check if the motion is “significant” enough, Scratch will convert it into a value — the faster the motion, the higher the value. Scratch will then start to run your code when this value is greater than the number on the block. You can control the sensitivity by changing the number in the block: 10 is very sensitive — you do not have to create a lot of motion to run your code — while 100 is not very sensitive, so a lot of motion is needed to start your code.

This can be used to interact with a sprite. For example, the blocks below will make a “Meow” sound when the user creates motion behind the sprite.

(20), play sound (Meow v) until done”>

### Motion and direction values

Scratch will also represent the direction of the motion it detects as a value. This direction value uses the same plane as sprite direction, so when you make a left to right horizontal motion on the video stream, the direction value will be 90.

You can use the video () on () block to get motion and direction values for a particular sprite or the entire Stage.

Follow the instructions below to create a project which uses the video () on () block to report the value of the motion on the Stage, and use this to set the volume of the sound that is playing.

1. Open a new Scratch project
3. Add the Video Sensing extension blocks, allowing camera access if you need to
4. Drag the blocks shown below to the Code area

5. Click on the green flag to run your program
6. Start dancing in front of your webcam

As you speed up your dance movements the volume will increase and as you slow your dance movements the volume will decrease.

### Creating a balloon popping game

You can also use the Video Sensing extension blocks as part of an interactive game. Follow these instructions to create a balloon-popping game:

1. Start a new project in Scratch
2. Add the Video Sensing extension blocks, allowing camera access if you need to
3. Position your camera so that your head and shoulders are on the Sprite Stage as shown below:
4. Delete the Cat sprite
6. Drag-and-drop the blocks below into your Code area

(20) play sound (Pop v) until done, go to (random position v), next costume”>

Now, when motion happens behind the Balloon sprite, you will hear a popping sound and the Balloon1 sprite will move to a random position on the Stage and change colour.

Choose one of the following ways to improve your balloon-popping game, and implement it:

• Keep track of the user’s score
• End the game after 60 seconds
• Make the balloon glide around while the user is trying to catch it