Taking Player Powerups away! More enemy AI advancement.
We’ve given 6 powerups to the player to help him combat enemy AI. So what happens if we take it away? What happens if the enemy, who I might add is growing smarter every article I write, decides that it can “see” the powerups? What happens if it can see the powerups AND decide to blow them up?
So that’s what I did. I gave the enemy AI even more brains. Now while it is travelling down it is sending out a “radar” of sorts and if it stumbles across a powerup, BOOM.. it takes it out.
If you read my last article where I gave 1 enemy the ability to fly to the bottom of the screen, stop and then go back and forth and fire whenever it detected the player in front of it then this won’t be too difficult.
In fact, it was pretty much a copy/paste (don’t tell my boss).
First, I created an agroRange variable that would hold the length that we want the enemy to be able to see. I then called the functions I create below in the update function:
Then, I went and created the functions that would help the enemy see and fire when the powerups where in line.
Ok, so all I did here was created (see: copied) a function like I did with the player detecting enemy. Had to change a few things though. You can see how I did this in the last article here:
Firstly, in the endPos I had to change the Vector3 to down as it is the enemy flying down. Then I created a FireLasersAtPowerup() that is called whenever the enemies raycast comes across the Powerup tag. Don’t forget to change all of your powerups tags.
So when the enemies “radar” shows a powerup in front of it it will run the above code. Basically just the normal enemy lasers except I got rid of the random.range and allowed the enemy to fire here when it needed too.
Let’s look how this plays out. I just made a “test” start and put a bunch of enemies behind the powerups.
Oh man, that’s nasty. You are going to have some angry players waiting to line up that one health powerup only to have it blown away.
Tomorrow, it’s a toss up between giving the player the power to press C and have the powerups magnetize towards him, or working even deeper with our enemy AI and give them the ability to dodge player laser!