In this video, you will program the racer to move up and down with the mouse pointerto avoid the obstacle. First, select the racer sprite. Click on thecostumes 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 numberedfrom negative 240 to positive 240. The y-axis extends from the top of the stageto the bottom, or vertically. It it is numbered from negative 180 to positive 180.
The numbers along the x and y axes are called “coordinates.” Every spot on the stagehas a pair of coordinates that represent its vertical and horizontal positions. To findout the coordinates for a place on the stage, hover the mouse pointer over that spot, andread the x and y values in the lower right corner.
Change the x value of the “go to” block to a spot on the left of the stage. This exampleuses “negative 190.” Then, open the “sensing” menu, and add a “mouse y” block to they value of the “go to” block. The “mouse y” block holds the current up and down positionof the mouse pointer.
Test out this 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 “goto” block.
Click this block stack to test it. Awesome! This sprite now follows the mouse up and downthe stage. The forever loop makes the sprite move towards the mouse over and over againforever. Lastly, add a “when flag clicked” blockto the top of this stack. Click the flag to see that it starts moving with this event.
Here’s the game plan: Program the racer to move up and down withthe mouse pointer using the “forever,” “go to,” and “mouse y” blocks.
In the next video, you will make an obstacle move across the stage.