Enemy Tries to avoid the Player Laser

Jason Schneider
2 min readFeb 9, 2022

Since our player is able to try and dodge the enemy lasers; I think; it is only fair we allow some enemies to do the same. In order to accomplish this we will first need to allow the Enemy to detect lasers that are fired. For this I have used a modified GetPowerUp method.

This script will return a Transform, therefore we need to create a new variable to hold this Transform. Such as:

We will then need to add the following:

GetLaserToDodge() is the modified GetPowerUp method.

to the Update method of our Enemy script.

Now; since we don’t want all our Enemies to have this ability; we need to introduce another variable. Such as:

Now, we need to add the following if statement to the EnemyMovement method:

This if statement has introduced a new variable and another Method, both of which we need to create:

and

The above Method has introduced a new variable; _dodgeSpeed; which we will need to add to the script:

Saving the script, jumping back into Unity, pressing play and then pause. Then setting the spawned Enemies, Dodge Ability to true and pressing pause again, will give:

--

--