Uninterrupted animation when falling

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

if is_on_floor():
on_ground = true
else:
if is_attacking == false:
on_ground = false
if velocity.y < 0:
animationPlayer.play(“JumpK”)
else:
animationPlayer.play(“FallK”)

	velocity = move_and_slide(velocity, FLOOR)

Here is the script, somehow I am the animation is cut when pressing right or left, or whenever the player moves

:bust_in_silhouette: Reply From: Gluon

I am guessing that you must have some other code which says if you press right or left then it should play a different animation. If you dont want that you could put a boolean guard in and then link animation finished to a function which switches the boolean guard back. So for instance pseudocode below;

var boolean = false 

func move():
    if press right and boolean == false:
        play right animation
    if press left and boolean == false:
        play left animation
    if press falling and boolean == false:
        play falling animation
        change boolean to true

func _animation_finished():
    change boolean to false
if is_dead == false:
	if Input.is_action_pressed("ui_right") && boolean == true:
		if is_attacking == false:
			velocity.x = SPEED
			animationPlayer.play("RunK")
			sprite.flip_h = false
			if sign($Position2D.position.x) == -1:
				$Position2D.position.x *= -1
			
	elif Input.is_action_pressed("ui_left") && boolean == false:
		if is_attacking == false:
			sprite.flip_h = velocity.x < 0
			animationPlayer.play("RunK")
			velocity.x = -SPEED
			if sign($Position2D.position.x) == 1:
				$Position2D.position.x *= -1
	else:
		velocity.x = 0
		if on_ground == true && is_attacking == false:
			animationPlayer.play("IdleK")
		
	if Input.is_action_pressed("ui_up") && boolean == false:
		animationPlayer.play("JumpK")
		if is_attacking == false:
				if on_ground == true:
					velocity.y = JUMP_POWER
					on_ground = false
					boolean = true
					
		
		
	velocity.y += GRAVITY
	
	if is_on_floor():
		on_ground = true
	else:
		if is_attacking == false:
			on_ground = false
			animationPlayer.play("FallK")
				
	velocity = move_and_slide(velocity, FLOOR)

This is the code, sorry if I got it wrong I am a newbie, somehow it work that the animation didn’t get interrupted when I pressed right or left key, the only problem is, is that the animation for falling would only show the 1st frame and get stuck in it until it’s on ground. Also when I jump, the animation for jumping would loop, it felt like it would loop whenever i am in the air and only after the fall animation is finished

GrandeHolt | 2022-12-22 10:36