BirdaoGwra i do it like this:
Double jump + coyote time
player.gd
var coyote_timer: Timer = Timer.new()
const COYOTE_TIME = 0.15
const DOUBLE_JUMP_TIME = 0.15
var jump_count: int = 0
var MAX_JUMP_COUNT = 2
func _ready() -> void:
coyote_timer.one_shot = true
coyote_timer.wait_time = COYOTE_TIME
add_child(coyote_timer)
func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("action_jump") and (is_on_floor() || (!coyote_timer.is_stopped() || jump_count < MAX_JUMP_COUNT ) ):
velocity.y = JUMP_VELOCITY
jump_count +=1
var was_on_floor = is_on_floor()
move_and_slide()
if was_on_floor && !is_on_floor():
coyote_timer.start()
if is_on_floor() and jump_count !=0:
jump_count = 0
Now this is the simple one that tracks mouse motion, and after no mouse motion it starts timer then after 1 sec reset. It changes the label.text to show the changes.
@onready var mouse_motion: Label = $Debug/VBoxContainer/MouseMotion
var timer = Timer.new()
func _input(event):
if event is InputEventMouseMotion:
mouse_motion.text = "Mouse_motion = true"
timer.start()
func _ready() -> void:
timer.autostart=false
timer.wait_time = 1.0
timer.timeout.connect(on_timer_timeout)
add_child(timer)
pass
func on_timer_timeout():
mouse_motion.text = "Mouse_motion = false"
You can see i have the outside function that does the change, and all the setting up is done in the _ready() function where you connect signals and add timers to tree