How to Make Enemy Move in Scratch

Aleena Martin on November 27, 2024

How to make enemy move on scratch

Introduction

 

Making games on Scratch is super fun and one way to make your game more exciting and competitive is by adding enemies! Enemies are characters or objects that make the game more challenging by attacking or blocking the player’s progress. On scratch we can create multiple enemies but the toughest part is knowing how to make an enemy move in Scratch. 

By the end of this article you will understand how to make enemies as well as make an enemy move in Scratch aka block-based coding platform, where the enemies can move, interact with the player, and even have different actions. Let’s get started!

What is Scratch?

Scratch is a fun, colourful coding platform where you create programs by dragging and snapping blocks together. It’s great for kids because it makes coding simple and easy to understand. You can create games, animations, and even stories! Today, we’ll focus on how to create enemies for your games.

Step by Step Guide

Step 1: Create Your Enemy Sprite

The first thing you need to do is create the enemy character you want. In Scratch, characters are called sprites. 

  1. Open Scratch and create a new project.
  2. At the bottom right, click “Choose a Sprite”
  3. If you want, you can add multiple costumes to your enemy so it can look different or have an animation when it moves.

Step 2: Make Your Enemy Move

Option 1: Enemy Moves Back and Forth (Patrolling)

This is a simple way to make your enemy move in a predictable pattern, like left and right or up and down.

  1. Select your enemy sprite.
  2. Use the “When green flag clicked” block from the “Events” category to start the movement when the game begins.
  3. Drag out a “Forever” block from the “Control” category. This will make your enemy move continuously.
  4. Inside the forever block, use “Move 10 steps” and then “If on edge, bounce” from the “Motion” category. This will make the enemy move back and forth across the screen.

Your code should look like this:

When green flag clicked
Forever
  Move 10 steps
  If on edge, bounce

Option 2: Enemy Chases the Player

Make the enemy chase the player - Make an enemy move in Scratch

If you want your enemy to follow the player around, here’s how to do it:

  1. Make sure you have a player sprite (like a cat or a person).
  2. Select your enemy sprite.
  3. Use the “Forever” block and inside it, add “Point towards [Player sprite]” and then “Move 5 steps”.
    1. The “Point towards” block will make the enemy always face the player.
    2. The Move” block will make the enemy follow the player.

Your code should look like this:

When green flag clicked
Forever
  Point towards [Player]
  Move 5 steps

Now your enemy will chase the player around the screen!

Step 3: Make the Enemy Interact with the Player

What happens when the player touches the enemy? In most games, the player loses health or gets hurt. Let’s make that happen in Scratch.

  1. Select your player sprite.
  2. Create a variable called Health by going to the “Variables” section and clicking “Make a Variable”. This will store the player’s health.

Set the health to ‘100’ at the start of the game:

 

When green flag clicked
Set Health to 100
  1. Now go back to the enemy sprite, if you want an action against even touching, you can do so.

Your code should look like this:

Forever
  If touching [Player]?
      Change Health by -10

This will make the player lose health every time they touch the enemy. 

Step 4: Add More Enemy Actions

Now that your enemy can move and interact with the player, let’s make the game more fun by adding different actions.

Enemy Disappears After Being Defeated

You can make the enemy disappear after the player hits it a certain number of times.

  1. Create a variable called  the ‘Enemy Health’.

Set the enemy’s health to ‘50’ at the start of the game:

 

When green flag clicked
Set Enemy Health to 50
  1. Use an “If” block to check if the Enemy Health is less than or equal to 0. If it is, use the “Hide” block to make the enemy disappear.

Here’s an example:

If Enemy Health <= 0
  Hide

Step 5: Add More Enemies

To create more than one enemy and make it more challenging, you can either duplicate your existing enemy and change its action or you can create entirely a new set of enemies with different movement patterns and interactions.

Test Your Game

Test Your Game - Easy tutorial to make an enemy move in Scratch

Now that you’ve added your enemies, we come to the fun part of the game, which is to test your gameplay! Click the green flag to start the game and see how the enemies behave. Make sure they move correctly and interact with the player the way you want them to.

If there’s a bug or something isn’t working, go back to the code and make adjustments. Coding is all about experimenting and fixing things until you get it just right!

Conclusion

Creating enemies in Scratch is a fun way to make your games more exciting and challenging. You can even create different types of enemies, each with its own actions, to make your game more interesting. Now that you know how to make enemies in Scratch, go ahead and try it out in your own game. 

Jump right on to fun coding courses, where your kids learn to adapt to the digital world of coding through simple and fun learning experiences! Let them join their first trial class today!

Encourage learning everywhere you go and have fun with your coding journey!

 

Sign up to our newsletter

Get the latest blogs, articles, and updates delivered straight to your inbox.

Share with your friends

Try a free class