Pump You Up

One trope of the shoot-em-up genre that I hadn’t yet tackled was implementing power ups in the stage which alter your base projectile attack. Unlike most other things with the UBH package, swapping between different shot patterns is awfully difficult. That, or I haven’t figured out the best way to handle it yet - but hey, it works!

Originally, I was trying to include prefabs of three different shot patterns as part of my Mount scriptable object (SO) and use logic inside of my ability macro to choose the correct one to assign as my player’s Shot Obj. But for some reason, if the shot script object isn’t attached to the player, it simply won’t fire. No errors or warnings get thrown, everything in the inspector seems cool, it just fires nothing.

 
Screen_Shot_2019-04-05_at_8_42_44_PM.png
 

Back to the drawing board. This time around I decided that not everything had to be the most modular, SO-driven code ever so I attached all three of the shots to the player object, created a pretty basic enum selector in the Mount SO:

public enum projectileStrength { basic, advanced, strong };

Screen Shot 2019-04-05 at 4.19.13 PM.png

In the hierarchy Projectiles is just an empty object to contain the mess, and each [FIRE] object contains a shot controller while their children contain a shot script. This actually provides a lot more flexibility than what I was doing previously, only swapping out the shot being fired. Now with unique shot scripts on each object I have control over the shot itself, but also its speed, acceleration, turn radius, etc. as well.

In the Bolt macro I’m initializing my basic shot to be whatever is selected in Mount, saving that to a graph variable, then on Update I’m checking it against any changes in Mount and updating accordingly by copying the shot list from that child object to the parent player object.

Screen Shot 2019-04-05 at 4.50.35 PM.png

When testing this functionality, I found if I ever changed ProjectileStrength while in the middle of firing I would end up firing both projectiles simultaneously with no way to shut it off. I included a unit to stop the shot routine before the shot list gets set and it fixed it right up 🐛🔨

Next up is implementing an item which could trigger these transitions. This part pretty much made itself. Colliding with the power up item triggers the PowerUp event which checks to see how strong your shot is, and boosts accordingly. If you’re already at maximum power, it fully restores your health and mana instead.

Screen Shot 2019-04-05 at 4.38.15 PM.png

And viola! It kind of worked! If you squint real hard in the grainy, weirdly sun-soaked gif below you’ll see a particle effect which triggers when I grab the power up. I’ve got the item disabling it’s sprite, but waiting until the particle effect disperses before despawning the object. This means it’s still sitting on top of the player, colliding and firing the PowerUp trigger over and over. Once I disabled the collider on trigger everything was all 🌈🥳

Screen Recording 2019-04-05 at 08.29 PM.gif

And here we’ve got the final product! With that settled the next things on the list are continuing to make All the Things™️ into scriptable objects while continuing to debug All the Things™️ which broke from being turned into scriptable objects. Progress!

Evan Lemmons

Husband, father, musician, gamer.