Player Thrusters Vs. Speed Boost Power Up
For our Game, The player moves some what slow because we want the player to feel a bit of ‘drag’ when flying the ship. And the Speed Boost Power gives them a nice jolt of speed when it is collected. But what about those times when the Player is in a bind and has to move away quick with the Power Up in reach. Let’s give them the ability to increase their speed at will for a cost. For now, let’s work on the functionality of the Thrusters or After Burners.
Problem: Giving the Player a way to temporarily and controllable increase movement speed.
Addendum: We want Player ‘AfterBurners’ to stack with ‘Speed Boost’ Power Up.
Solution: Add another element to the movement equation when calculating Direction and Speed.
Control new Element from outside the Movement() so that we can adjust it later and introduce a cost to using the function.
For this new Functionality, We will be working solely inside the Player Class as this will be something unique to the Player and only effects the Player themselves.
We will need two new Variables for the basic system. _thrusterBoostAmount will be for the Designer to adjust the Power increase. _thrusterBoostMultiplier will sit in the Translate function and be switched between 1 (off) and the Amount (on).
The Thruster() will be how we introduce the change of Speed/Power to the system. We will assign the Left Shift key as the Input for using the ability. note that we are using GetKey and NOT GetKeyDown here. This is because we want to know when the key is being held. GetKeyDown or GetKeyUp only read when the key is first pressed or released, respectively.
In the Movement(), we add the _thrusterBoostMultiplier to the transform.Translate() to have the ability effect it’s change on the Ship’s velocity. (Highlighted above for ease of location.) We can leave the line as it is or we can pull the equation out and into it’s own variable handler to shorten the line. Coder preference I believe, but it may present a cleaner look to your code over all.
And by adding the Thruster() into Update(), we finally bring the functionality into the Game Play loop.