I want that if the player goes +2 or -2 taking into account the x position of the player before pressing left or right, the fall animation change and keeps changed (even if turning to the other side) until the player lands.
https://imgur.com/a/964KXn6
Here's my code:
extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const MAXFALLSPEED = 200
const MAXSPEED = 80
const JUMPFORCE = 300
const ACCEL = 10
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
motion.x = clamp(motion.x, -MAXSPEED, MAXSPEED)
if Input.is_action_pressed("ui_right"):
motion.x += ACCEL
$Spr_P.set_flip_h(false)
if is_on_floor():
$AnimationPlayer.play("Walk")
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jump")
elif motion.y > 0:
if position.x + 1:
$AnimationPlayer.play("Fall Forward")
else:
$AnimationPlayer.play("Fall")
elif Input.is_action_pressed("ui_left"):
motion.x -= ACCEL
$Spr_P.set_flip_h(true)
if is_on_floor():
$AnimationPlayer.play("Walk")
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jump")
elif motion.y > 0:
if position.x - 1:
$AnimationPlayer.play("Fall Forward")
else:
$AnimationPlayer.play("Fall")
else:
motion.x = lerp(motion.x, 0, 0.2)
if is_on_floor():
$AnimationPlayer.play("Idle")
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jump")
elif motion.y > 0:
$AnimationPlayer.play("Fall")
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = -JUMPFORCE
motion = move_and_slide(motion, UP)