diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-11-14 10:45:04 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-11-14 10:45:04 +0200 |
| commit | cb5ddada498a44e8569bdf53359ee06ee11e3d44 (patch) | |
| tree | fc52d60d612067b2fa43f9f9b800f7fc44d531ad /player.gd | |
| parent | bce80184961866e0efcc227becf15fe66bd99428 (diff) | |
Add coyote time
Diffstat (limited to 'player.gd')
| -rw-r--r-- | player.gd | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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 |
