This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote

When the caracter slash with an axe, the stamina bar's (wich is a TextureProgress) value -= 30. And I created a Timer node, wich used for wait like two seconds after the slash, to refil. It works, but ONLY at the first time, after that the stamina immediately refils. Do you have any idea, how to solve this probelm?

The codepart:

func onstamina_timeout():
stamina = true

func physicsprocess(delta):
if active == true:

    if stamina == true:
        if s.value < s.max_value:
            s.value += 0.5
Godot version 3.2
in Engine by (18 points)

1 Answer

0 votes

I always have problems with the timer so I just use process since it gives informations in seconds with the ms portion be in the decimal portion of the float value.

enum StaminaState {WAIT, FILL, DRAIN}

var stamina_state = StaminaState.FILLED
var stamina = { "Value": 10,  "MAX": 10 }
var time_to_wait_before_filling_in_seconds = 1
var time_passed = 0

#delta in seconds
func _process(delta):
   match stamina_state:
         #if stamina value less max, increase else keep the same
         if time_passed >= time_to_wait_before_filling_in_seconds:
               stamina_state = StaminaState.FILL
               time_passed = 0
              time_passed += delta
         time_passed = 0

Any time an action is done

  • Decrease Stamina Value if stamina value greater than 0
  • Switch back to Drain State to reset time
by (98 points)

Thank you! It's kinda working!

make sure in Drain state to make it so that it changes stamina_state to WAIT and that any action switches back to DRAIN

         time_passed = 0
         stamina_state = StaminaState.WAIT
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.