Creating a Thruster Boost in Unity!

O'Daiyah Harper
4 min readJun 14, 2022

--

Objective: Learn how to create a thruster boost in Unity.

Let’s go ahead and set everything up!

First, we want to set up the animator for our boost.

We can use the same thruster sprite we are using currently. All we need to do is scale it up a little and we should have the animation working!

Now, when we play the animation, we can see the change in how the thruster is affected!

Let’s go ahead and set up the parameters we will need. Luckily, we only need one!

We need to add the boolean parameter to check if the player is using the thruster booster or not.

We can now add the transition from and to the booster animation.

For both, we change Has Exit Time to false and the Transition Duration to 0, so that it can automatically play the animation.

Now that we have the animator all set up, let’s start getting into the code!

We’re going to need a couple of variables in order for this to work. We have to create a boolean that will keep track of whether or not we’re holding down the key.

Next, we need to create a thrust speed and change our speed variable to normal speed. I will provide an explanation later on in this post.

Lastly, we are going to need a reference to the Animator component on the thruster.

We are also going to need a reference to our current speed, so it will be easier to change our speed depending on if the thrusters are being used.

We are going to have to grab the Animator component that’s on the thruster by using GetComponentInChildren.

For this example, we are going to use the left shift key for the booster. We can have the thrusting boolean equal to if we’re holding down the key.

If thrusting is true, we will have the current speed become the thrust speed. However, if it is false, we have the current speed be the normal speed.

Now, we need to have the animation play. To do that we can use Animator.SetBool(). This method needs a string and boolean.

The string will be the name of the parameter we previously used for the Animator. We can utilize the thrusting boolean that we currently have in the script, as well.

We would then need to switch the normal speed variable to the current speed variable, so that way we can visibly see the change!

Awesome! We can see our animation and the speed change come to life! I will come back to this in the future to add another feature to it! As the next chosen feature, I will be adding shield strength!

--

--