Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BigBackPack |
Hey, I have this problem with the state of is_on_floor on my kinematicBody2D while runing/moving only on the x axis. The state is always switching even though the player is not leaviing the ground at all. Any help would be grat
her is my code:
extends KinematicBody2D
export var velocity = Vector2(0,0)
export var slide = 0.2
const SPEED = 280
const JUMPFORCE = -900
const GRAVITY = 30
var flyJump = true
func _physics_process(delta):
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = lerp(velocity.x,0,slide)
if Input.is_action_pressed("right"):
velocity.x = SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
else:
$AnimatedSprite.play("idle")
if Input.is_action_just_pressed("jump"):
if flyJump == true:
velocity.y = JUMPFORCE
if is_on_floor():
flyJump = true
if !is_on_floor():
coyoteTime()
velocity.y += GRAVITY
print("xxx")
$AnimatedSprite.play("jump")
func coyoteTime():
yield(get_tree().create_timer(1), "timeout")
flyJump = false