Benefits of Timer Nodes?

Godot Version

Godot-4

Question

I’m making a 2D platformer, and implemented coyote time. Upon doing some research after the fact, I found that most people do this using timer nodes. I did not do this and was wondering if there were any benefits to using a timer rather than a variable that counts down every frame. Would it be worth changing to use a timer node instead?

In case it helps answer my question here is my coyote time implementation:
“Coyote time”
if wasOnFloor and not is_on_floor():
coyoteTimer = 6

if is_on_floor():
canJump = true
elif coyoteTimer > 0:
canJump = true
else:
canJump = false

wasOnFloor = is_on_floor()
if not is_on_floor():
coyoteTimer -= 1

“Handle jump”
if Input.is_action_pressed(“ui_up”) and canJump:
velocity.y = JUMP_VELOCITY
if Input.is_action_just_released(“ui_up”) and velocity.y < -200:
velocity.y = -200

1 Like

The main thing would be that it’s affected by the time scale and less code as the timer node exists, is tested and you just need to connect the signal.

Depending on where you run your code, make sure to think about delta time. If you just decrease the coyoteTimer variable by one each tick it might depending on frame rate.

1 Like

Yeah, this is in the physics process. I hadn’t considered delta time affecting this, but now that I think about it, that’s a pretty fair problem. I think I’ll switch to using timers so as to not have to worry about delta time. Thanks.