The ,,Coyote Jump" is intended to work like this:
After the Player leaves the Floor, they should have a small time window in which they can still jump,
because Human brains aren't perfect:
In platformers without this mechanic, almost every player, including me, will complain about
how the game often doesn't register the press of the jump button.
The topic of this discussion is, that I need help to eliminate an unwanted side effect:
In the moment, the player can double-jump if they double-press Jump really fast, but I don't want that in my game.
This is my current Player Movement Script (Embedded atop the Player Scene):
# youtu.be/wETY5_9kFtA # youtu.be/BfQGXtlmE7k
# youtu.be/vFsJIrm2btU
extends KinematicBody2D
const UP = Vector2(0, -1)
var motion = Vector2()
const speed= 100
const gravity = 10
const jumpHeight = -200
var coyoteTimer = 0.0
const coyoteTime = 0.2
var running = false
# var jumping = false
var floored = false
func _physics_process(_delta):
motion.y += gravity;
if Input.is_action_pressed("right"):
motion.x = speed
$Sprite.flip_h = false; running = true
elif Input.is_action_pressed("left"):
motion.x = -speed
$Sprite.flip_h = true; running = true
else:
motion.x = 0
running = false
if is_on_floor():
floored = true
else:
floored = false
if Input.is_action_just_pressed("jump"):
if coyoteTimer < coyoteTime:
motion.y = jumpHeight
motion = move_and_slide(motion, UP)
func _process(delta):
if floored:
coyoteTimer = 0
else:
coyoteTimer += 1 * delta
animate()
func animate():
if floored == true:
if running == true: $Sprite.animation = "run"
else: $Sprite.animation = "idle"
else:
$Sprite.animation = "jump"