My Jump animation freezes when I move left or right mid-air

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ampv2002

Whenever I move my character mid-air the jump animations freezes, but when I don’t move the animation plays just normal I would like some help here. Here’s the code (P.S: Im using Animated Sprites):

extends KinematicBody2D
const salto = Vector2(0, -1)
const gravidade = 15
const velocidade_max = 150
const altura = -700
const aceleracao = 50
var movimento = Vector2()
var isAttacking = false
var on_ground = false
var input_vector = Vector2()
func _physics_process(delta):
	movimento.y += gravidade 
	var friccao = false
	input_vector = Vector2.ZERO
	if Input.is_action_pressed("ui_right"):
		if isAttacking == false || is_on_floor() == false:
			movimento.x = min(movimento.x+aceleracao, velocidade_max)
			if isAttacking == false:
				$Sprite.play("Run")
				$Sprite.flip_h = false
	elif Input.is_action_pressed("ui_left"):
		if isAttacking == false || is_on_floor() == false:
			movimento.x = max(movimento.x-aceleracao, -velocidade_max)
			$Sprite.flip_h = true
			$Sprite.play("Run")
	else:
		friccao = true
		if on_ground == true && isAttacking == false:
			$Sprite.play("Idle01")
	if Input.is_action_just_pressed("ui_up"):
		if isAttacking == false && is_on_floor() == true:
			movimento.y = altura
			input_vector.y = 1
		if friccao == true:
			movimento.x = lerp(movimento.x, 0, 0.2)
	else:
		if friccao == true:
			movimento.x = lerp(movimento.x, 0, 0.89)
	if Input.is_action_pressed("ui_attack") && isAttacking == false:
		if is_on_floor():
			movimento.x = 0
			$Sprite.play("Attack01")
			isAttacking = true
			yield ($Sprite, "animation_finished")
			isAttacking = false
	movimento = move_and_slide(movimento, salto)
	if is_on_floor():
		on_ground = true
	else:
		if isAttacking == false:
			on_ground = false
			if movimento.y < 0:
				$Sprite.play("Jump")
				yield ($Sprite, "animation_finished")
				if Input.is_action_just_pressed("ui_attack"):
						$Sprite.play("AirAttack")
						isAttacking = true
						yield ($Sprite, "animation_finished")
						isAttacking = false
			else:
				$Sprite.play("Fall")
				if Input.is_action_pressed("ui_attack"):
					$Sprite.play("AirAttack")
					isAttacking = true
					yield ($Sprite, "animation_finished")
					isAttacking = false
	pass
func _on_Sprite_animation_finished():
	isAttacking = false"
:bust_in_silhouette: Reply From: Merlin1846

Looks like your walking animation is set to play even when your not on the ground. Try useing.

if is_on_floor():
    #All the code for the animation goes here

that’s what I use.