timers not working is intended?

Godot Version

v4.5 stable

Question

don't even know how to ask this :O

[USING LINUX MINT]

I am a Godot newbie so it is entirely possible that this is user error, but all three of my overclocked brain-cells think this is a bug.

I was trying to make a FPS game in Godot and wanted to implement coyote time in blender,(letting the character jump for a few milliseconds after falling off a ledge)

so I use the timer node, basically i want timer to start the second player leaves a floor (falls off a ledge) if the player presses space before the timer ends the jump registers and doesn’t if player was too late to start.

however the code written below let’s me jump after way after one second from the player falling.

[trying to debug my problem you can see the now commented code where i asked it to print wait time, and time left when coyote jump happened both outputs gave me the exact same number, the number was the one i set in timer properties through UI (example- 2.873 seconds) instead of the value of ‘cayote_timer’ variable]

(also I didn’t know how to spell coyote till typing this post sorri :D)

	
@onready var timer: Timer = $Timer
@export var cayote_timer = 1
var jump_permission = 1
var jump_permission_reset = 1

func _physics_process(delta: float) -> void:

# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta * gravitymult
		timer.start(cayote_timer)

# Handle jump.
	if is_on_floor():
		jump_permission = jump_permission_reset

	if Input.is_action_just_pressed("ui_accept"):
		if player.is_on_floor() or jump_permission > 0:
			jump(JUMP_VELOCITY)
			print("jumped")
			$"ConvertedByVirtualSp eech-Imqpu0o6h2".play()
        #if player.is_on_floor():
			#jump(JUMP_VELOCITY)
			#print("jumped")
		#if !player.is_on_floor() and timer.time_left > 0:
		#	print("time left = ", timer.time_left)
		#	print("wait time = ", timer.wait_time)
		#	jump(JUMP_VELOCITY)
		#	print("cayote_jump")

func _on_timer_timeout() -> void:
	jump_permission = 0
	print("Cayote out")

also trying to debug I made it so that the timer started in ready function, manually set to 10 seconds and print Cayotied, i made 3 attempts to make it output Cayotied.

#1 output was spammed.

#2 & #3 no output was displayed.

[ready function]
timer.start(10)

[physics process function]           #1
if timer.timeout:
    print ("cayotied")

if timer.time_left == 0:             #2
    print ("cayotied")
or 
func _on_timer_timeout() -> void:    #3
    print ("cayotied")

is this a bug or is it just me being dumb?

(if I forgot to add something lmk)

This runs every frame the player isn’t on the ground, including starting (or restarting) the timer, it never times out because it is reset too often. Maybe it would be better to start/restart the timer while you are touching the ground? This could also reduce the amount of variables you need.

if is_on_floor():
    timer.start()

if Input.is_action_just_pressed("ui_accept"):
	if player.is_on_floor() or timer.time_left > 0:
2 Likes

I’m not going to repeat the reply above mine but I will instead hopefully give you code that will work exactly how you would want for your coyote jump time functionality.

var coyote_time : float = 5
var coyote_timer : float = coyote_time
func _physics_process(delta: float) -> void:
	coyote_timer -= delta
	if is_on_floor():
		coyote_timer = coyote_time
		jump_permission = 1
	elif coyote_timer > 0:
		jump_permission = 1
	else:
		jump_permission = 0

This is pretty similar to gertkeno’s code but all internal. This requires no Timer node.

Code Summery: When player is on floor he will cause the timer to stay at 5. When he leaves the floor the coyote_timer will start counting down to 0 and below. If the player is on the floor or coyote_timer is higher than zero, jump_permission will be 1. If he is not on the floor and coyote_timer is less than 0, jump_permission will be 0.

Hope this was useful.

1 Like

This was really helpful, I ditched the timers entirely since I don’t exactly understand them. (:
(p.s. I’m aware of my unhealthy use of variables, I’m discussing it with my therapist)

This was great help I can Coyote jump now, not having to use timer node is the best part.
although I can double if I press the key fast enough but that’s a separate issue to be solved another day.