Booster UI and Camera Shake


A bar now displays when the player is boosting.
The boost can now only be held until the bar is full and may be pressed again when the bar is disappears.
Overview

I have my player’s speed cut in to three variables.
Bases speed is use to move the player and is modified when shift is held or a power up is retrieved.
Thruster speed is base speed multiplied by a number and is used when shift is held.
speed is used as a reference to our base speed. This variable is used to return base speed to its original speed when its modified by boosting.
I have two coroutines that will increase the players base speed until its approximately greater than or equal to thruster speed and one that will decrease the players speed back to its original speed.
These coroutines will be only be called when the player holds shift. Additionally, there are two IF statements to check if the values go beyond thruster speed or our speed reference.

Camera shake is done by simply calling a trigger parameter that was set up in our camera’s animator. Our parameter ,’Shake’ will be triggered whenever this method is called
Coroutines

The coroutines will execute every 0.5 seconds and will increment or decrement base speed depending on which one is called. A float variable will be passed through either coroutine so I may adjust to my liking.
As the name suggests, Accelerate will increment and Decelerate will decrement.
After the players speed is changed, we will call out update boost method from our ui script and modify our BfloatTrigger parameter made in our animator.
These will affect the UI and the thruster animation on our player.

The update booster ui method simply changes the value to the attached slider ui object. One float variable is passed to this method so we may add or subtract the slider’s value.
Boost

This IF statements are checked within our movement method and will call the proper coroutines when the player has held left shift or has released the key.
Holding left shift key will call the accelerate coroutine until it reaches its max speed (thruster speed). Once it reaches its max speed, itll set our canboost boolean to false which will disallow the player to boost any further.
then we’ll check if base speed is incremented past thruster speed. If it is, it’ll reassign base speed to thruster speed for corrections.
Letting go of shift will do the inverse operation to our first if statement.
Conclusion

Now we have a short boost that can be used to dodge incoming enemies or reach for a power up.