2D Game Dev Journey — Day 23: Aggressive Enemy and Enemy Shields
Welcome to 2D Game Dev Journey — Day 23: Aggressive Enemy and Enemy Shields. Today I go over how I implemented an enemy that can “ram”, as well as a way for our player to attract nearby pick-ups.
Today we will be starting right where we left off in 2D Game Dev Journey — Day 22: Smart Enemy and Pick-Up Magnet.

To get set up for today, I went ahead and created the enemy that will be our aggressive enemy type.

Aggressive Enemy
As per usual, there are a few ways one can go about implementing this enemy, but I specifically took advantage of inheritance and polymorphism, as well as coroutines, to get this enemy properly working. By doing this, my code for this enemy ended up being only 44 lines.

Below is how the enemy looks in-game.

Honestly, I am pretty happy with this. The only change I would make is changing my raycast to a circle cast so that the enemy has a greater radius in which to detect the player. I will probably do this in the future.
Enemy Shields
When it comes to enemy shields, my goal is to allow any enemy to have a shield upon being spawned. These shields only take one hit, and I set the probability for an enemy to be spawned with one to 25% (at least for now). This is how they look in-game.

Conclusion
Thanks for checking in and reading today’s article. Tomorrow I will be creating the final enemy type, as well as a way for our enemies to destroy power-ups. If I have made any mistakes, please let me know so I can correct them for future readers. If you would like a more in-depth tutorial about anything I went over today, let me know and I will take the time to write something up.