Coyote timer code not working

Godot Version

v4.6.1

Question

I’m trying to figure out how to store my jump inputs when in air. Im not sure why it isnt working. The code makes no difference and my jumping still only works when I press jump after Im on the floor. It doesnt even return an error. I tried to include as much of the relevant code as I could. Sorry if I missed anything important.

func _physics_process(delta: float) -> void:
 move_and_slide()
 var jump_timer := 0
 if (Input.is_action_just_pressed("Jump") and jump_timer <= 0) and not is_on_floor():
	jump_timer += 60
 if jump_timer >= 1:
	jump_timer -= 1
	
 var is_just_jumping := (Input.is_action_just_pressed("Jump") or jump_timer >= 1) 

 if is_just_jumping and is_on_floor() and not aim:
	velocity.y += jump_velocity
	_skin.jump()

_physics_process gets executed many, many times per second. And at every iteration, it seems like you set your jump_timer variable back to 0 at the start. You likely have to move this variable outside of your _physics_process, or alternatively, you can use Time.get_ticks_msec() to get the time elapsed since the game started, and subtract the previous time from it in the next _physics_process iteration when your player pressed the jump button again. See how big the differene is, and do something based on that.

1 Like

Omg, tysm! It works now.

1 Like

A small caveat here. Don’t use Time.get_ticks_msec() in _physics_process(). Details here: Time.get_ticks_usec() in _physics_process()? - #14 by normalized

Sure, but I never suggested it should specifically be used inside physics process. I just suggested that as an alternative to what OP is trying to do.

It sounded like you suggested subtracting two Time.get_ticks_msec() readouts in consecutive _physics_process() calls.

Using Time.get_ticks_*() to measure time in _physics_process() will result in accuracy problems because _physics_process() doesn’t necessarily run in real time, depending on ticks settings.

It’s always preferable to use delta.

1 Like