Boosting the player

PieceofPhie
3 min readApr 14, 2021

The player can now be ,’boosted’ when holding down shift. The player’s speed will increase by half of its base speed. Allowing the player to quickly move out of danger or snag a power up at the last second.

Overview

I declared two new variables, made some changes to the speed boost method, and created a method for our player movement. There’s also a visual to our ships thruster when pushing boost.

Variables

Base speed will be the inherit speed that the player moves without boost. Its incremented every time the player grabs a speed boost power up and it directly influences our player’s movement.

Max speed is….well the max speed inherit speed that the player will be able to reach.

speed is used to keep a reference of our base speed at all times. Whenever the player picks up a speed boost power up, its reassigned accordingly. This variable exists because returns the player back to its original speed value after boosting

Thruster speed handles how fast the player moves when boost is pushed. This variable will be assigned and multiplied to our base speed whenever the player presses shift key. Thruster speed can be adjusted via inspector for fine tuning.

Movement Method

This method checks for shift input and if shift is not being pressed.

When shift is pressed, base speed will equal speed multiplied by thruster speed. It will also set our animation trigger(ThrusterON) to true so that our animation will play. When shift is not being pressed, the inverse occurs.

These executions are all being done before we translate our player so that the player will move according to any change in speed value from either boosting or speed boost power ups.

You may notice that there is a boolean called,’IsDodging’. I was working on a dodge mechanic while scripting the boost, but didnt finish in time. It may be another article in the future.

Speed Power Up Method

our speed reference needs to be updated whenever our base speed increases from power ups. We simply reassign speed to base speed after our base speed is incremented in our speed boost method.

Result

--

--