Journal 37 — Negative Power Up in Unity

In this article, I updated one of the power ups and changed it to a negative effect.

The concept in this case is to use a Speed Up power up, but change it slightly to make it greatly affect and reduce Player movement.

To start, we can take the basic Speed Up power up, and modify it slightly to make it a little deceiving while collecting power ups in the middle of a game.

Unity Playmode, differences in modified power up

Next, we can update the switch statement in the Powerup C# script to add an additional power up option.

Unity C# script for Powerup, add negative speed to switch statement

Over in the Player C# script, we can add the function to start the negative speed impact. We will use some bool variables to make the negative speed true, and also make sure the thrusters are disabled in order to really impact the player.

Unity C# script for Player, negative speed function

In the Player’s movement function, we will update speed and thruster conditional statements and loop through the conditions whether speed up is true, or negative speed is true, or whether the player can use thrusters.

Unity C# script for Player, speed changes in Calculate Movement function

In order to spawn the negative speed power up, we need to update the SpawnManager script. I used a random number generator with a few conditional statements depending on the power up for each spawn, with some conditions that spawn a more basic power up (e.g., speed up, triple shot), to a more rare special attack power up, and the last power up is the negative speed we just created, for powerUps[6].

Unity C# script for SpawnManager, add negative speed as one of power ups to spawn

Finally, we can see the big impact in Playmode.

Unity Playmode, Speed Down impact

Thank you for your time!

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.