How can I implement a “run bar” in Godot 4?

I want to implement a mechanic in my 3D game that limits the player’s ability to run. The player should have a “bar” that appears when they hold shift. This bar depletes while the player runs and regenerates over time when the player stops running. (Similar to the mechanic in Baldi Basics). Are there any tutorials or YouTube videos that demonstrate how to implement such a mechanic? Any help would be greatly appreciated. Thanks in advance!

This is not that difficult:

  1. Create a progressbar and design it however you like
  2. Set its max_value and min_value
  3. create a script for it (the constants can also be exported so they can be configured in the inspector):
extends ProgressBar

const RESOURCE_LOSS_PER_SECOND: int = 5
const RESOURCE_GAIN_PER_SECOND: int = 5

var is_active: bool = false

signal exhausted

func _physics_process(delta: float) -> void:
    if is_active:
        value = max(value - RESOURCE_LOSS_PER_SECOND * delta, min_value)
        if value == min_value:
            # handle exhaustion. I'll use a signal
            is_active = false
            exhausted.emit()

    elif value < max_value:
        value = min(value + RESOURCE_GAIN_PER_SECOND * delta, max_value)

now to reduce the progress-bar you just have to set is_active to true.
4. you can add a appear and disappear animation with tweens if you want to

1 Like

Thanks, for your help!