The next task is for me to make my own secondary fire power up and I’ve decided to create a multi-direction shot. This power up will last for 5 seconds and spawns rarely.
For the multi-directional shot, I’ve spawned 8 projectiles moving in 8 different places: up, down, left, right, upper-left, upper-right, lower-left and lower-right:
The code for moving in different directions look like this. Notice that the values for upper-left, upper-right, lower-left and lower-right represent each quadrant of the cartesian plane:
As for spawning rarely, I’ve assigned weights to each power up of the Spawn_Manager.
Basically, every 3 seconds, any of those power ups could be chosen. However, a random number between 0 and 100 is also generated. If the chosen powerup’s weight is greater than or equal random weight then that power up will be instantiated. Otherwise, another random powerup will be chosen as candidate and random weight generated and the process will repeat again.
When the power up is enabled, you need to make sure that it will only be available for 5 seconds:
Then, you need to be able to instantiate the Spread prefab when Fire is pressed and the power up is active.
Without further ado, a new secondary fire power up is born: