Day 22: Adding Extras — Thrusters

In this article we’re going to implement a Thruster feature. When we press left Shift the player will be able to move at an increased speed. We’ll have the thruster animation happen, and a UI element that shows us how much thrust we have left.

Our player script will need the following:

Here I’m basically setting the speed to whatever we have thrusterSpeedset to when Left Shift is pressed. I’ve named our GameObject that we set active (the thruster that shows behind the player) “Thrusta” because I’m a straight up G. We set it to active when left shit is pressed and inactive when its released. Easy peezy. thrustCurrent is set to 1 on start. We refer to this value in a new script called FillStatusBar. It looks like this:

This will makes sense when you see the inspector:

As you can see, the Value of the Slider goes from 0–1. Thats why I have thrustCurrent set to 1 in start on the player. When we press left shit the bar goes down. When it hits zero we disable the functionality. Check it out!

There are ways to make this prettier. I’m no artist, so a simple slider will have to do for now! Until next time!

--

--

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