Prototype: Enemy Movement


In the last post, we added an attack cooldown for the player attack. Now it’s time to move on from the player and begin prototyping an enemy!

The Challenge

Our challenge is to create an enemy prefab with a 3D primitive, a material to make it stand out from the player, and provide basic movement behavior.

Let’s go started.

Create The Enemy

I’ll use another Cube for the enemy but change the transform scale to 0.75. Let’s make sure the enemy stands out in the prototype by creating a new Material and giving it a color of #F16868.

The Enemy Cube

Add Enemy Movement

Now let’s add some movement by creating a new Enemy script and attaching it to our Enemy GameObject. I want the enemy to move down the screen with a speed configurable via the inspector.

When the enemy goes offscreen, let’s reposition it to be in a random horizontal position and above the screen so that it will downward again in a new position. This way, the number of enemies will increase over time, and we’ll reuse any that the player has not destroyed.

Player Movement Code

Finally, I’ll make this a prefab that we can use to instantiate enemies later in the prototype.

Enemy Movement


We now have an Enemy prefab that knows how to move and reposition itself in a new random horizontal position and offscreen vertically.

Stay tuned for the next post.
Take care.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s