Adding Thruster Scaling Bar Hud

Previously, I’ve added a thruster to speed up movement by holding left shift and setting speed back to normal after releasing it. This time around, we will be implementing resource consumption and cooldown for the Thruster or it wouldn’t be fair. We will also allow the player to see how much thruster is being used and how much of it is being refilled.

First, I repurposed a Slider and make it act as a scaling bar:

This is the code to update the scaling bar. Notice that I used delegate so that the UI is only updated when thruster level has changed. You can also see from the code that the color indicator changes from nothing to red, yellow and green depending on thruster level.

Then on the Player, I had to update the Thruster code to calculate consumption. I used this formula to consume Thruster level:

On the other side, I used this formula to regenerate Thruster level:

For balance, I made sure recovery is slower than consumption. Also, thruster recovery needs a cooldown period first:

Here’s the full code for the Thruster:

Now, I have a running thruster with cooldown.

I love game design and development.