2D Certification: Enemy destruction of powerups

2D Certification: Enemy destruction of powerups

Christopher West
2 min readSep 7, 2022

In the last article, I implemented a smart enemy type. Today, I’m going to be continuing the second, and final, phase of the GameDevHQ 2D Game Development Certification track. In this article, I’ll be adding the ability for the enemy to destroy powerups! The requirement reads as follows:

Tasks:

  • If a pickup is in front of an enemy, the enemy will fire its weapon at the pickup to destroy it before the player can get it.

For this requirement, I started by adding Box colliders to my existing powerup prefabs and set their tags to “Powerup”, a new tag I created with the tag editor. Next I chose to add the ability to pass in a target’s transform to the enemies Fire method and expose the method via the IFireLaserBehavior interface. Passing in the target’s transform allows for angle calculations based on the given target.

I then Added the ability for Enemies to detect powerups to the Enemy script and wired up the detection to happen in the Update method.

Lastly, I then added the collision detection code to the powerups that handles collision with enemy lasers and had the powerup destroy itself when hit by an enemy laser.

With that, and after some play testing, I had given the enemies the ability to destroy powerups!

Next Time!

In this article, I added the ability for the enemy to destroy powerups. Next time, I'll be adding a pickup collect feature! If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.

--

--

Christopher West
Christopher West

Written by Christopher West

Unity Game Developer, Software Engineer, Gamer, Musician, and Father. Christopher is a creative that enjoys a challenge and loves coding.

No responses yet