Step 6: Initializing the Rock Speed

Goal:


Let’s set up our rock’s speed to start moving in a random direction and random speed.

We can do this by setting up the variables we just created from the last step.

This is very similar to what we did for the fish, save for one thing. What is that difference? Why is there that difference?

Steps:

  1. Stay on the “Rocks” sprite.
  2. From Control, place a when green flag clicked block.
  3. From Variables, place two set to blocks.
  4. Change one to xSpeed and the other to ySpeed.
  5. From Operators, grab two pick random blocks and place them inside each set to blocks.
  6. Set the number on the left side of the pick random block to -5 and the right side to 5.
  7. From Looks, place a show block.

Code: