Enemy avoids lasers feature

Jaime
Jun 21, 2021

--

The next requirement is to allow the enemy to avoid a shot. I’ll be using the same algorithm with power ups which is for the Enemy to detect the laser’s presence:

Then, I added these attributes to handle evade detection. Basically, I’ll be suspending normal movement and randomize x and y movement if enemy detects the laser. Also, if enemy evades, this movement will need to power down back to regular movement. There’s also the _evadeWeight attribute to make sure that only some enemies can do this.

In OnTriggerEnter2D of the Enemy is where detection, generating random x and y movement and cooldown are implemented:

Then evade movement will commence when _suspendNormalMovement is true.

Now, the enemies can evade lasers:

--

--

Jaime
Jaime

No responses yet