Creating Modular Powerup Systems

Speed Power Up

So here I wanted to add a speed power up to the game that was modular and easily editable later on, incase we need better balance. We first needed to add the Speed Power up object that we named Speed_Powerup.

Then added a Box Collider 2D and checked the Trigger button as this will be a trigger. That will say “if this object is hit then increase player speed”.

Box Collider 2D

Next we will be adding our RididBody2D and setting our Gravity Scale to 0 as we don’t want our object to be falling off our screen as gravity was applied.

Now we are going to create a script in which we can control all of our powerups in one place. No need to create a script for each of our objects when we can just use a one to control them all. This will also make it very easy to adjust things later on.

So we create a variable for the speed in which our power up will move and create a variable that will store an ID. This is where this script will be used for multiple powerups.

Here we are controlling that trigger and collider we created earlier. We are saying here that if the other object is the Player then do the following based on what ID we assign to the power ups. Here we assign an ID of 1 for the speed powerup. This will run SpeedBoostActive() method within our player script.

Within our player script we have just created a couple of variables for our _speed one being our speed that is default set at 4f and our speedMultiplier that is 2.

Below our method is ran and see a Boolean that is set to true saying that speed boost is active. Then we make speed which is 4 times, the multiplier which is 2. So we essentially double our speed to 8.

Since we can’t have double the speed for the entire game we need to make sure that this only last a certain amount of time. So we went ahead and created a coroutine called SpeedBoostPowerDownRoutine and this just says wait 5 seconds and then set the speedBoostActive Boolean to false. Return our _speed back to normal. Basically dividing current speed of 8 by 2 which is 4 our original speed.

In created a very modular power up ID script we can use this to attach to any of our power ups and just change their IDs. The only thing that we would need to do is just add the new behaviors with the desired effects and add to our switch statement.

We have just made our game very easy to edit and add features later on by doing just a little extra work now. Thanks for reading!

--

--

--

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

Recommended from Medium

A Distributed Database Middleware Ecosystem Driven by Open Source

Basic syntax for using tensors in Python using Pytorch

Magic of Saturn controllers

Jenkins Master Slave Configuration (Ubuntu Master & Windows Slave )

We built a robot to detect bad real-time data

What is Asana and Why Should We Use It?

How to Turn Excel into a Web App with Drag & Drop

How To Set Up A Medium Article Feed On Your Blog

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
Richard Carpino

Richard Carpino

More from Medium

Unity Dev Blog: How to Build and Test Your Unity Game

Installing Unity & Getting Started with Game Development

Downloading Unity

Making Camera Shake using Impulse Listener Extensions

Made With Unity | 2D Space Shooter Part 4: The Enemy