DevLog #2 - Creating powerups


This blog is only intended for fun educational technical talk of the game and not aimed for those who are trying to follow step by step to recreate, therefore there may be lots of steps skipped and/or not shown.

Up to this point I have completed the 'base' game and am starting to add extra things to game. So far the game is playable with a player, asteroids and enemy ships. The player can shoot the asteroids, enemies and enemy ships. I'm also confident at this point that the game is bug free.

Powerups

Note that all the powerups all have similar setups. This is just what i found the most convenient setup to match the current setup. It will be a game object with a collider that will trigger whatever the powerup is.


Health packs

Lets start with the easiest powerup. To do this I create a game object 'healthpack'. It will need a rigidbody with gravity turned off, box collider set to istrigger and finally a healthpack script. I use my previous script 'Mover' to move the game object toward the z axis or towards the bottom from the top. Then it is just a case of increasing the player's health when the player collides with the healthpack game object. First I get the player game object:


Then get the health variable of player and increase it by an amount:


Speed boost

As mentioned above, the setup will be similar in that it will be an empty game object and a trigger box collider that will trigger a speed boost, this is also fairly easy. The only difference between this type of boost is that it has a timer as opposed to just increasing a value by a fixed amount. There is a timer involved so in the update function, I have this code on my player script:


speeding being a bool, speed  being the current speed, speedTimer being 5 (or 5 seconds). With this I can create a script on my speedboost game object and simply trigger speeding to true on trigger enter which will increase the speed of the player for 5 seconds.


Triple bullet boost

This mechanic will be very similar to the speed boost. It will have a timer of 5 seconds and for the duration the player's attack speed will increase slightly and fire 3 bullets instead of 1. To do this I instantiate from a different array of bullet spawns in my player prefab. In my player script I have this code:


When the boolean tripleShotActivated is true, the fireRate increases and the timer goes off. The boolean becomes true when  the trigger on the game object of the boost is with the player.

As for the shot spawns I have an array of shot spawns(total of 3) and if the triple shot is activated, bullets will instantiate from 3 of those spawns instead of just 1 when its turned off:



That is all for this blog, thank you for reading, as I update the game I will create more blogs, stay tuned.