From cb5ddada498a44e8569bdf53359ee06ee11e3d44 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 14 Nov 2025 10:45:04 +0200 Subject: Add coyote time --- player.gd | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'player.gd') diff --git a/player.gd b/player.gd index 4fce64e..cc2a663 100644 --- a/player.gd +++ b/player.gd @@ -2,10 +2,15 @@ extends CharacterBody2D @export var speed: float @export var jump_strength: float +@export var coyote_max: int var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var prev_dir: float = 0.0 +# coyote = 0 indicates on floor +# coyote > 0 indicates frames since on floor +var coyote: int = 0 + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. @@ -26,8 +31,13 @@ func _process(_delta: float) -> void: func _physics_process(delta: float): velocity.y += gravity * delta + if is_on_floor(): + coyote = 0 + else: + coyote += 1 - if Input.is_action_just_pressed("jump") and is_on_floor(): + var can_jump = coyote < coyote_max + if Input.is_action_just_pressed("jump") and can_jump: velocity.y = -jump_strength var direction: float -- cgit v1.3