How can I disable a function after input and resume after timeout?

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

Hi all. I am trying to write a script that will move an object on input.is_action_pressed but once the keys have been pressed I want to disable that function for a few seconds and resume it afterwards. How can I do that?

Let’s says up arrow gives a rigid body linear velocity on the Y axis. I want the player to only hit up arrow once, set the object in motion, but at the same time i want the up arrow input to disable itself for, say, 4 secs, so that once it was hit once further hits do not move the object until the function is ‘resumed’ (with a timer I guess).

Appreciate your help.

I was thinking (which doesn’t work):

var canjump = bool(true)

func _input(InputEvent):
if Input.is_action_pressed(“ui_up”)
set_linear_velocity(Vector3(blah blah))
canjump == false
if canjump == false:

:bust_in_silhouette: Reply From: estebanmolca

You can use yield corroutine:

func printer():
	yield(get_tree().create_timer(5.0), "timeout")

See yield in the documentation.