Science Oxford Logo

Make an Enemy Move

As well as adding projectiles, you can make your enemy or other sprites move around the game as well.

For example, to make the pancake machine move, we need to find its set-up instructions in the on start loop, and add a movement block.

From the Sprite menu, find the set mySprite velocity to vx 50 vy 50 block, and add it underneath your sprite set-up code - remember to choose the correct sprite!

Screenshot of blocks - set Machine position to x 138 y 101, set Machine velocity to vx 50 vy 50

Your sprite will now start moving in a diagonal direction - you can change vx and vy to decided the direction and speed - do you want it to move up and down, across the screen, randomly?

To stop your sprite from disappearing off the side of the screen, look in the Sprite menu for the set mySprite bounce on wall block, and add it to your code - does it do what you expect?

Screenshot of blocks - set Machine position to x 138 y 101, set Machine velocity to vx 50 vy 50, set Machine to bounce on wall ON