Creating a enemy that shoot backward when the player is behind in Unity

Objective: Create a new enemy type that starts shooting backward when the player is behind.

First I just duplicated the enemy prefab and assigned a new enemy ID.

Then in the enemy script in the shoot laser routine I added a condition to check if the enemy ID is equals to 3 and the “y” position of the enemy is lower than the player. Then I just rotate the instantiated enemy laser by 180 degrees and with that change the enemy laser is gonna move backward.

As simple as that you have an enemy that shoots backward when the player is behind.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.