Adding Thrusters Boost & Thruster Boost Animation

This is a simple and fun feature to add in my game. When the player holds the Shift button down, it will give their speed a boost and when the Shift button is released it will go back to the original speed.

This requires a different input detection. Usually what is used is the Input.GetKeyDown and pass in the key you want to get. This will only detect if the button was pressed during the current frame, but if held down it will no longer be detected. Using Input.GetKey will continue to detect if the key is being held down. So, we will use KeyCode.LeftShift to specify the key we want and increase the speed variable. Since an IF ELSE statement is being used the else will hand when the Left Shift is release and the speed variable is returned.

Now when I hold down the Left Shift key down the player moves faster and when I release the Left Shift it returns back to the original speed. But visually nothing was changing. I felt the speed but I needed to see it too. So I wanted to decrease the thruster image for when the space craft is moving at normal speed and increase the thruster image when the thrusters are being applied (Left Shift Key Down).

Currently, the thruster image is a child of the player and it has an animator controller and a looping animation. This will be used as my thruster boost animation, so I will need to create a new animation for the normal speed.

Create a new animation by simply recording the thrusters at a smaller size. Now, I’ll head back to the animator controller and make the new animation the default state from entry.

I need to create a transition from the small thrusters to the boost thrusters and be able to call it from the script. This means a boolean parameter needs to be created and applied to the transitions between both states. If Thrusters (parameter) is true it will go to small thrusters to thrusters and if it is false it will transition back from thrusters to small thrusters.

Let’s go to the Player script so we can get a handle on the Animator and call it when we are holding down the Left Shift button. Since the animator is on a child of the Player we will need to use GetComponentInChildren instead of GetComponent and assign it to our _animator variable. For best practices we will perform a Null check.

Going back to IF ELSE state where we are increase the speed if the Left Shift key is down, we will set the animator boolean to true so it triggers the big thrusters animation and when the Left Shift key is release that boolean is set to false return the animation back to the small thrusters.

This gives us that visual of boosters actually being used when the player speed increases. Now, I just have to add a sound component to go along with it. That can be another article.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

‘NaN’ You May Not Know

Cyclically Rotate an Array By One

What’s new in Create-React-App v4 & React 17

Jackson Tips: ObjectNode.putPOJO(), putRawValue() for fun and profit

GraphQL Authentication with Elixir and Absinthe

How to use Forms in Angular4

Introduction to Big O Notation

Comma, Pipeline, Nullish Coalescing and more unique Javascript Operators

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan McCoach

Ryan McCoach

More from Medium

OnCollisionEnter() vs. OnTriggerEnter()

Mastering Unity Scripting by Alan Thorn

Cover of the Mastering Unity Scripting book

The Ultimate Guide To Start Making 3D Video Games

Day 96: How To Upgrade Your Project to URP in Unity