In this video you will program
the racer to move up and down with the mouse pointer
to avoid the obstacle.
First, select the racer sprite.
Click on the costumes tab and select the racer
that you want to use in this activity.
Then, add a go to block to the stage.
In Scratch the stage is a coordinate plane.
You may have learned about coordinate planes in math class.
The X axis runs across the stage
from left to right or horizontally.
It is numbered from -240 to positive 240.
The Y axis extends from the top of the stage
to the bottom or vertically.
It is numbered from -180 to positive 180.
The numbers along the X and Y axes are called coordinates.
Every spot on the stage has a pair of coordinates
that represent its vertical and horizontal positions.
Change the X value of the go to block
to a spot on the left of the stage.
This example uses -190.
Then, open the sensing menu and add a mouse Y block
to the Y value of the go to block.
The mouse Y block holds the current up and down position
of the mouse pointer.
Test out the block by clicking on it.
Great, the sprite moves to the left of the stage
and moves up and down
according to the location of your mouse
when you click on the block.
However, this sprite should keep moving
to the mouse's Y position forever.
To do this, open the control menu
and add a forever block around the go to block.
Click the block stack to test it.
Awesome, the sprite now follows the mouse
up and down the stage.
The forever loop makes the sprite move towards the mouse
over and over again forever.
Lastly, add a when flag click block
to the top of this stack.
Click the flag to see that it starts moving with this event.
Alright, here's the game plan.
Program the racer to move up and down
with the mouse pointer using the forever,
go to and mouse Y blocks.
In the next video, you will make an obstacle
move across the stage.
Sign in to track your progress and earn badges