Skip to content

Please update your browser

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

2. Following the Mouse Pointer


In this video, you will program the player sprite to follow the mouse pointer.

To start, select the player sprite. Next, click the motion menu, and drag out a "go-to mouse pointer" block. When you click it, the sprite will go towards the mouse pointer's location. In this case, the mouse pointer is in the scripts editor, so the sprite goes to the right edge of the stage. The sprite needs to follow the mouse. That means that the sprite needs to go to the mouse pointer over and over again, not just once.

To do that, use the “forever” block. Now, when you click on this block stack, the sprite will go to the mouse every time. Good! Next, add an event to tell the computer when to run this code. Use a "when sprite clicked" event, which tells the sprite to follow the mouse pointer when the sprite is clicked.

Great! Finally, try it out to see if it works. Click the sprite. Don’t click and drag the sprite, but instead click and release it. To stop the program, click the stop sign.

Nice job! Now it’s your turn! Program your player sprite using: 1. A go to ‘mouse pointer’ block 2. A forever block and 3. A ‘When this sprite clicked’ event Remember, if you have a question while working, ask a neighbor or get the attention of your CS First Guru.

arrow_backward Back
Next arrow_forward
  1. Make the sprite follow the mouse pointer.
  2. Make the sprite follow the mouse pointer forever.
  3. Make the sprite follow the mouse pointer when the sprite is clicked.