top of page
Search

Split-Ball Powerup

  • Abbie Hipwell
  • Apr 7, 2022
  • 2 min read

Updated: Jun 11, 2022


The team decided that powerups would be a necessary mechanic in the game after our Beta Test, the game was very slow paced and needed features which encouraged competitiveness. The split ball powerup works when the player shoots; three balls will be fired closely after one another in a 'cone' shape, increasing the chance of hitting the enemy player.


This is the main code for the powerup ...



At first I created this powerup using three iterations of the code which spawns the ball, and used a sequence to do this three times. Although this method worked it was very un-optimised. Instead I was able to use a For Loop, which was set from 0 - 2, meaning the code would be ran three times.


I changed the rotation of the ball using the code below; I got the original spawn point of the ball and used a 'break' node to change the roll (rotating the ball left and right), pitch (moving the ball up and down), and yaw (moving the ball left or right in its direction). I only needed to change the Z (Yaw of the ball), so I created a custom float variable for this so each ball would head in a different direction. This is then added back to the rotator.



The For Loop will connect to SpawnActor BP Ball, alongside the vector 'return value location' and the rotator. The player who spawned the ball needs to be set, as otherwise the ammo can collide with them and cause the barrier to move in the wrong direction.


The Z Yaw Powerup variable is set by adding five onto the existing variable. Initially it is set to -5, meaning the first ball will be directed slightly left, the second will be set to 0, meaning the ball will head straight, and the third will be set to 5, meaning it will be directed slightly right. This allows the balls to form a 'cone' shape.



I first tried using a regular for loop for the powerup, however for loops cannot work with delays. A delay was necessary for the powerup to work as otherwise the balls would spawn at the same time and collide with one another. I attempted to adapt the collisions for the ball so they could all spawn at the same time, however felt this was unnecessary as a delay would work just as good using less code.


Since for loops cannot be used with delays, I had to create my own custom Macro, which can be seen below.



This code will work when the player fires ammo and Powerup Ball Split is set to True. The player doesn't need any ammo for this to work, as it is a powerup.






Once the For Loop is complete, the Z Yaw Powerup will be set back to -5, Destroy Split Ball is set to True, which means the three balls that have been spawned will be removed, and Powerup Ball Split is set to False, meaning the powerup cannot be used again until another is picked up.






 
 
 

Comments


bottom of page