I want to add coyote time in my 2d platformer in godot but I was unable to make it work. here is my code, I learned GDscript 2 weeks ago and i am by no mean an expert I tried changing the code order which just made the code break many times with no results, coyote time never did work here is the code if you find any mistake or something that can be improved, I would love to read it even if it's not about coyote time. extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 9
const SPEED = 150
const JUMP_HEIGHT = -400
var motion = Vector2()
var coyote_time
var is_jumping = false
var was_on_floor = is_on_floor()
func _ready():
coyote_time = Timer.new()
coyote_time.one_shot = true
coyote_time.wait_time = 2.0
add_child(coyote_time)
$AnimationTree.active = true
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("move_right"):
motion.x = SPEED
$Sprite.flip_h = false
$AnimationTree.set("parameters/state/current", 1)
elif Input.is_action_pressed("move_left"):
motion.x = -SPEED
$Sprite.flip_h = true
$AnimationTree.set("parameters/state/current", 1)
else:
motion.x = 0
$AnimationTree.set("parameters/state/current", 0)
if coyote_time.is_stopped():
motion.y += GRAVITY
if is_on_floor():
is_jumping = false
if Input.is_action_just_pressed("jump"):
is_jumping = true
motion.y = JUMP_HEIGHT
elif not is_on_floor() and was_on_floor and not is_jumping and Input.is_action_just_pressed("jump"):
coyote_time.start()
is_jumping = true
motion.y = JUMP_HEIGHT
else:
if motion.y < 0:
$AnimationTree.set("parameters/state/current", 2)
else:
$AnimationTree.set("parameters/state/current", 3)
motion = move_and_slide(motion, Vector2.UP)
pass