0 votes

So I made a script in which if the player touches and Area node, a Timer will start and I want a progress bar (TextureProgress) to jump to max and climb down and reach zero when the timer runs out.

Godot version 3.3.2
in Engine by (55 points)

3 Answers

+1 vote
onready var bar = $progessbar
var progress = 0
var cooldown = false
var bar_speed = 2.5

func _process(delta):
    bar.value = progress
    if cooldown:
        progress -= bar_speed
        if progress <= 0:
            cooldown = false


func on_area_enterd(body):
    cooldown = true
    progress = 100 # or max value

2.5 bar speed is 1 second so if you have a timer of 5 secs do 2.5*5 so bar speed will be 12.5

by (264 points)

It works!!! My only problem is that the * the bar speed calculation doesn't work. Example:
I have a 10sec cooldown and if I use 2.5 * 10 thats 25 but the UI element will go even faster. So 2.5 * X isn't correct. What else calculation can I use to get the same exact speed as the Timer?

2.5 = 1 seconds and your doing progress -= 2.5 so instead of multiplying

bar_speed = 0.25
0 votes

see this link from kids can code.
It not with a progressbar, but you can change the code to your use case.

by (114 points)
0 votes

use the timer time_left function for the progress bar value

by (430 points)
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 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 webmaster@godotengine.org with your username.