Currently trying to make a progress bar go up over 1 second, only path I seem to know how of doing this is by doing:


Variable = time

min value = variable
max value = variable+1

while ( variable < max time )
variable = time


This is just code written out in theory, I just can't seem to find out how to make a "variable = time", I would have considered the Timer feature in Godot but it goes down rather than upwards ( I assume since its a timer ).
Any advice is helpful.

In C#.

  • xyz replied to this.

    Have a time variable. In the _process function (_Process in C#, I believe) add the delta to the time variable. There is your time since startup (or at least since the game started rendering).

    Also, never do this kind of while loop in Godot. This is effectively busy-waiting. It breaks everything.

    You seem to be asking two different things. Getting the time since the game started is simple:
    https://ask.godotengine.org/84641/is-there-anyway-you-can-get-the-elasped-time

    but if you're just looking to lerp a progress bar, just start at 0 and use delta.

    @export var lerp_duration = 1.0
    
    var lerping = false
    var lerp_time = 0.0
    var lerp_percentage = 0.0
    
    func start_lerp():
    	lerping = true
    	lerp_time = 0.0
    	
    func _process(delta: float) -> void:
    	if lerping:
    		lerp_time += delta
    		lerp_percentage = lerpf(0.0, 1.0, lerp_time / lerp_duration)
    		if (lerp_time > lerp_duration):
    			lerping = false

    TigwerSparkz Best to use tweens for time driven progress bars.