Small speed boost with Player Thrusters

Our Player can already grab a Speed Boost that allows them to go super fast for the duration of the Powerup, but how about we give them a slight boost when holding the Shift key to escape dire situations?

In this article we’ll implement Player Thrusters when holding the Shift key, but give them a limit to how long they can use it. We’ll utilize UI fill amounts and let it regenerate over time!

Thruster usage and regeneration

Creating the Thruster Logic

Since this Thruster enhancement will be affecting the Player, we’ll creating the logic inside the Player script.

First we’ll create a bunch of variables relating to the Thruster usage:

  • _thrusterSpeedMultipler = how much speed will be gained using the thrusters
  • maxThrusterFill = arbitrary amount that denotes the max to fill to
  • currentThrusterLevel = the starting level of the thruster, and updated to denote the current thruster level
  • _thrusterUsageAmount = how much thruster fuel will be used while holding the Shift key every second
  • _canUseThrusters = a bool to help with regeneration, and stoppage of using thrusters once it runs out
  • _thrusterCooldown = time to wait when thrusters become depleted

And now our Thrusters logic:

We’ll be creating the UI interaction soon

Thruster Cooldown Routine:

Simple and effective

And utilizing our new function in our PlayerMovement() so that it can use our directionInput local variable inside this function.

The regeneration logic

Thruster Level UI

You’ve seen the _uiManager.UpdateThrusterFill() a couple times now…It’s time to actually create the UI element that it will be Updating!

The Thruster Level UI

First, the normal text:

Simple Text attached to our Canvas

Then we’ll create the Black Border to surround the red fill:

And the Thruster Fill that will be updated:

The main essence of this element is the Image Type. It is set to Filled, which gives us some more options to work with: Fill Method, and Fill Origin.

After setting it to the appropriate position and size, it’s obvious we want it to fill horizontally and not vertically (you could do a vertical one, for sure. It would just have to be placed different from mine).

And the Fill Origin determines which way the Fill comes from. You can play with the Fill Amount slider to see how your UI element would be updated.

UIManager Script

Now we’ll create the reference variable to our new Thruster Fill UI and link it in the Inspector:

And finally create our fancy new UpdateThrusterFill() function:

Since we’ve already referenced the _player in this script, we can now get the public variables we created earlier when we want to Update our Thruster UI.

Just like that, we can move a little bit faster and have our Thruster Level visually represented and updated in real-time!

In the next article, we’ll be jumping back to our Player Shields. This time, since the game is going to get much harder, we’ll be giving them 3 chances before their shield is destroyed. Of course, that will be visually represented as well!



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