I am trying to implement a multi state jump animation however my script will only play the Idle animation when in the air.
extends KinematicBody2D
var velocity = Vector2(0,0)
const SPEED = 140
const GRAVITY = 35
const JUMPFORCE = -550
func _physics_process(delta):
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE
if not is_on_floor():
if velocity.y < -200: #going up
$AnimationPlayer.play("jumpoff")
elif velocity.y < -50:
$AnimationPlayer.play("jumploop")
elif velocity.y > -50 && velocity.y < 10.0: #transition
$AnimationPlayer.play("landing")
else: #falling
$AnimationPlayer.play("fallloop")
if Input.is_action_pressed("right"):
velocity.x = SPEED
$AnimationPlayer.play("walk")
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$AnimationPlayer.play("walk")
else:
$AnimationPlayer.play("idle")
velocity.y = velocity.y + GRAVITY
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.1)