Enemy movement!

addam davis
2 min readJun 29, 2021

Objective: Give the enemies some movement variations.

In the current state of the game, enemies are instantiated and move straight down making them an easy target. We are going to give random enemies a slight turn to the left and the right. It doesn’t sound like much of a maneuver, but remember, it was good enough for Han Solo.

Make an int variable to represent the vector input for your enemy’s X axis.

We need to update the translate function on the enemy.


Now we need to create a method to determine the value of our enemy’s angle.

We want this value to change when we instantiate another enemy, so we want to call this method from the spawn manager. So, every time the spawn manager instantiates the x axis is assigned randomly.

Now we need to set the enemy limit for the x axis. Similar to the player if the enemy goes past a certain point, we them to rap around to the other side of the screen.

That’s all there is to it. The enemies will now move and an angle making the game that more realistic. You can make the angle more extreme if subtle depending on your preferences. Don’t be afraid to experiment with your code and I’ll see you in the next tutorial.