Phase 1: Thrusters
Objective: Add thruster mechanics to the player.
So in order to get thrusters working we need to be able to adjust the speed. Like we did for the speed powerup, we will set a serializable private float to use as a thruster speed multiplier.
As an addition to making the player faster while thrusters are on, some visual feedback would be a nice touch. For this we set a serializable private game object for the thruster attached to the player and assign it in the inspector.
Next within the update method, we run two if statements, one to check if the left shift is pressed and the other if the left shift key is released. Each option calls to its specified method. Pressed calls the thrusters activate and released calls thrusters deactivate.
As you can see above, the logic between both is similar. In activate we multiply player speed by the thruster speed multiplier and deactivate divides. We set a Vector3 scaler variable and on activate set the thruster object attached to the player to the larger scaler and on deactivate, set the scale back. While scaling the object, the position slightly moves so we create a Vector3 thruster position and adjust the y position of the transform for cleaner presentation.
In the next post, we will look more at the players shield behaviour.