Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

3. Control the Racer


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 negative 240 to positive 240. The y-axis extends from the top of the stage to 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 stage has a pair of coordinates that represent its vertical and horizontal positions. To find out the coordinates for a place on the stage, hover the mouse pointer over that spot, and read 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 example uses “negative 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 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 “go to” block.

Click this block stack to test it. Awesome! This 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 clicked” block to 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 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.

arrow_backward Back
Next arrow_forward
Program the racer to move up and down with the mouse pointer using the "forever," "go to," and "mouse y" blocks.