How to make a cooldown bar?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 20xxdd20

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.

:bust_in_silhouette: Reply From: lewis glasgow
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

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?

20xxdd20 | 2021-08-11 15:03

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

bar_speed = 0.25

lewis glasgow | 2021-08-11 20:52

:bust_in_silhouette: Reply From: aipie

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

:bust_in_silhouette: Reply From: vnmk8

use the timer time_left function for the progress bar value