Zdc360
Zdc360

Reputation: 1

Creating sprinting and stamina mechanic in 3d Godot game

I’m creating a 3d doom like game and I want to create a sprinting mechanic that will lower the stamina bar, then once that bar reaches 0 it should stop you from sprinting.

My current code:

Player.gd (this is in process delta btw)

    if Input.is_action_pressed("Shift") and $"../../Control".stamina >= 1:
        SPEED = sprintspeed
    else:
        SPEED = 5

Stamina.gd

func _process(delta):
    if Input.is_action_pressed("Shift"):
            value -= 0.505

func _on_timer_timeout():
    if value <= 99:
        value += 1

Almost everything works, the sprint bar decreases when shift is pressed, and regens when released, it sets the speed to the sprint speed (15) and sets it back to 5 when released. But when it reaches 0 it doesn't stop you from sprinting.

Upvotes: 0

Views: 84

Answers (1)

Not a privileged user
Not a privileged user

Reputation: 963

In Stamina.gd you are setting some 'value' variable.

But in the Player.gd you are reading from Stamina a 'stamina' variable.

Upvotes: 0

Related Questions