Creating Delay timer for jumping

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

Hello! I’m still new to Godot and game devolping in general. Anyways I want to create a timer that starts when the player isn’t on the ground. I will use this timer so the player will be able to jump 0.4 seconds after he has fallen from the platform.

I don’t have any idea how to do it, but I have tried this:

#Movment Variables
const jump_force = -500

func _physics_process(delta):
#Input for vertical movment
	if is_on_floor(): #checks if player is on floor

        #Timer to check if 0.4 seconds have pasted
		timer = Timer.new()
		timer.set_wait_time(1)
		timer.connect("timeout", self, "")
		add_child(timer)

		if (Input.is_action_pressed("move_up")):
			motion.y = jump_force

#Movment of player
	move_and_slide(motion, Vector2(0,-1))

As you see I haven’t connected the timer to a function. Bcs I thought it would be inefficient to make a whole function to just test if the timer is done. I also don’t know how to implement the timer into my if statement. So if there is any way to do it, I would be happy to know

//Marre

:bust_in_silhouette: Reply From: Magso

Add delta to a float and reset it every time the jump is landed.

var jump_timer : float

if is_on_floor():
    jump_timer += delta
    if (Input.is_action_pressed("move_up") and jump_timer > 0.4):
        jump_timer = 0
        #won't start timing again until is_on_floor() is true
:bust_in_silhouette: Reply From: usurun

You can also make a timer node. This node has four properties. You can configure it and then do the get_node(“timer_node”).start().

Also, you have to link the timeout signal if you want to play something when it finishes.

yield (timer_node, “timeout”) will wait in script.

Thanks for the good info!

Marre | 2019-07-13 20:23