2D Game Dev Journey — Day 18: Rare Power-ups

Welcome to 2D Game Dev Journey — Day 18: Rare Power-ups. Today I go over how I implemented a rare power-up I have named “heated shot”.

Starting Point & Setup

Today we will be starting right where we left off in 2D Game Dev Journey — Day 17: New UI & Ammo Implementation.

To get set up for today, I digitally painted a little fireball to act as our main sprite for this power-up.

Once imported, I also made the collectible that activates the power-up.

Rare Power-up Implementation

Below is the heated shot power-up in action. As you can see, this power gets hurled at the enemy, and when it comes in contact with one, it expands and destroys any enemies that come into its radius.

Now implementing this power-up was a pretty involved process. For one, since this is a rare power-up, I had to set up the probability this power-up gets spawned. For now, I have the probability set to 5%, which equates to a rare power-up being spawned once for every 20 power-ups spawned. To do this, I utilized the built-in Random.value static float property. This property returns a random float value between 0 and 1 (inclusive). Using this as I have below allows me to control the probability at which certain power-ups are spawned.

Code-wise, I also had to implement some script communication between enemies and the heated shot GameObject. This also included adding another property to my PowerupType enums list.

Now other than code, to get the above effect I need to do some decent animation work, and I actually learned a few things along the way. For one, I learned that any child of a GameObject with an animator component automatically gets associated with their parent GameObject’s animator. This allows for a developer to animate all GameObjects pretty easily that are grouped together. I also learned I can animate properties of the particle effects I was using as part of the whole VFX.

The first part of the heated shot animation
The second part (explosion/expansion) of the heated shot animation

Above are the animation windows for the heated shot power-up. For this, I did have to create two separate animations. One to act as the idle animation (the first animation), and the second animation is to help create the explosion/expansion effect. Tying together all these different components gave me the result seen earlier at the start of this section. I definitely still want to work on the VFX for this one a bit more, but I’m happy with it for now.

Same GIF as earlier in the section

Conclusion

Thanks for checking in and reading today’s article. Tomorrow I will be changing up the background to match the style a bit more, as well as implementing a negative power-up that shuts down the player’s systems for a few seconds. If I have made any mistakes, please let me know so I can correct them for future readers. If you would like a more in-depth tutorial about anything I went over today, let me know and I will take the time to write something up.

--

--

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