Adding Rarity to Power-Ups: GDJ 23

Brett Blandford
2 min readJun 8, 2021

With the addition of the drone shot power-up, my game now has 6 power-ups. Some are more powerful than others, so I wanted to make a system that makes some power-ups rarer than others. These are the powerups and their rarity: Ammo and speed are common, triple shot and shield are rare, and Drone Shot and extra life are very rare.

To implement this, I added a method in the SpawnManager script called DoesPowerUpSpawn().

This method takes an int which will represent a power-up. If you recall, the power-ups are in an array, and this powerUp argument is the index of whatever power-up was chosen in another part of the script.

The index of the power-ups can be assigned in the editor. The common power-ups have the index of 0 and 1, the rare power-ups have the indexes 2 and 3, and the very rare power-ups have indexes of 4 and 5. You might be able to figure out how this works with this information, but I explain more after I show where the place where this method is used.

So to sum the whole process up, we start with determining a random power-up index that then gets put into the DoesPowerUpSpawn() method. If the random index is a 0 or 1, the method returns true and the power-up is spawned. If the random index is 2 or 3, this index goes through another random number check. If the random number is less than 80 out of 100, this power-up gets spawned. The same thing occurs with the index of 4 or 5, just the random number as to be less than 50. This means that a very rare power-up has a 2/6 chance of getting selected, then has a 50% of spawning after it is selected. These numbers could easily be adjusted to balance a game, and I might even make variables so I can access them in my editor!

There are plenty of ways to do this, but it was fun to come up with my own method! (No pun intended)

End of GDJ 23!

--

--