Implementing Speed Boost in Unity

Harvey Limbo
2 min readApr 15, 2021
Boosting!

For today’s article, I’ll be going over how I add speed boost to the player ship.

Unity Editor Setup

In the Unity Editor, I created an empty game object named Thruster as a child object of the Player. Next, I added an Animator component and placed in the image frames to create the boost animation.

Boost animation

The Code

In the Update() function of the Player script, I moved the logic into a private helper function called CalculateBoost() to keep calculating movement and boosting the ship separate.

In the CalculateMovement() function, I multiply the speed variable with a currentBoostMultiplier variable. If currentBoostMultiplier is set to 1, the ship will move at normal speeds. If currentBoostMultiplier is set to a number greater than 1 (e.g. 2), then the ship will be moving at twice its normal speed.

Setting Thrust Boost keys in Input Manager

To see more of the code, please visit https://github.com/hlimbo/Space-Shooter-Tutorial

Thanks for reading :)

--

--