Adding an afterburner

Hal Brooks
2 min readJul 1, 2021

--

Objective: Provide a player speed boost while holding the left shift key down.

Added afterburner with visual effect

To add a visual effect for the afterburner, duplicate the Thruster, naming it Afterburner. Set the Afterburner to inactive by clicking on the check box near its name. Reduce the scale of the Thruster to (X 0.5, Y 0.5, Z 0.5).

Added afterburner to Player

In the Player script, three new variables are required.

Required afterburner variables in Player script

Define the GameObject variables in void Start().

Null checking game objects for the afterburner in Player script

In void Update() within the Player script we add the code below. The if statement checks for the LeftShift key to pressed. To avoid crazy speeds the bool variable _afterburnersOn is checked to see if afterburners are already on. If they are not on the _velocityMultiplier for movement is multiplied by two, _afterburner animation is set to active, _thruster animation is turned off, and the bool is set to true. If the left shit key is not down in the frame then the _afterburnerOn is checked to see if the afterburner is engaged, and if it is true then the _velocityMultiplier is divided by two, _afterburner animation is set to inactive, _thruster animation is turned on, and the bool is set to false.

Code for afterburner in void Update() Player script

Below is the movement code showing how the _velocityMultiplier is used to increase the speed.

Movement function within Player script

--

--

Responses (1)