Zac Bogner

Jul 19, 2021

3 min read

2D Space Shooter: Powerups! Negative Effects For The Player Controller

In-Game Powerups are great for difficulty curves and progression.

Objective: Providing a way to negatively effect the player progression by collecting a negative effect powerup.

Powerups can be used for both good and bad scenarios towards the player.

In the image displayed above, I implemented the negative powerup by allowing the player controller to freeze itself for a time allotment.

Lets take a look at how I approached the negative effect feature.

First, we need to get reference to our Player Controller.

  • Check if the player is not null
  • Assign player speed = 0
  • Normalize the player position
  • Set Boolean to true

Second, we create a type of IEnumerator to call at the end of our NegativeEffect function.

  • Yield return 5 seconds before deactivating the effect
  • Set player speed = 3
  • Yield return the player transform position
  • Set the Boolean to false

Once we have these functions made, we can now call the NegativeEffect inside the PowerUp class.

Within the powerup class we have an OnCollisionEnter2D method to handle the powerup behaviors.

To do this, we get reference to the player controller and pass in the collision

We setup a switch statement to structure the powerups for activation when the player controller collides with them.

This setup allows for a modular powerup system to easily add and remove powerups as desired based off of the number of powerups we have.

So now that we can apply negative effects to our player controller, there are many more ways to add or subtract player controller behaviors through game mechanics.

Next, we will look into completing the rest of our remaining game features in the upcoming articles.