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!

Happy Clicking!




With Unity all can be accomplished!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Hyperscale Data Centers

Humanoid Robots, Autonomous Fighter Drones, and Computers Than Can Code: What’s Next?

Beirut AI Community Recap: February 2020

Reinforcement Learning Demystified: Markov Decision Processes (Part 2)

How is AI Changing Fashion Design or Helping a Clothing Designer?

Artificial Intelligence in Procurement — From Insight to Action

What’s Wrong with AI Tools and Devices Preventing COVID-19?

Eight learnings from the 2021 Deep Learning Barcelona Symposium

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
Laine Dorchester

Laine Dorchester

With Unity all can be accomplished!

More from Medium

Speed. I am Speed.

Making a Dash Mechanic for your game

Benefits of Prototyping with Cubes

P6: Creating a Gritty Office Den