• 2D
  • Problem with AnimationPlayer and diagonal movement

So i'm new to Godot and i have the next code in my player node (KinematicBody2D); Everything works without any problem, except that when my character walks diagonally, the animation gets stuck on the first frame and it won't advance to any of the next frames. If i, for example remove the "right" and "down" movements, the "right-down" animation plays without any issue, but then i won't have the original 4-way animations. How can i fix this??

var velocity = Vector2()
func get_input():
	velocity = Vector2()
	
	
	if Input.is_action_pressed('right'):
		velocity.x += 1
		$AnimationPlayer.play("Walk_side")
		$Sprite.scale.x = -1
	else:
		if Input.is_action_just_released("right"):
			$AnimationPlayer.play("Idle_side");
	
	
	if Input.is_action_pressed('left'):
		velocity.x -= 1
		$AnimationPlayer.play("Walk_side")
		$Sprite.scale.x = 1
	else:
		if Input.is_action_just_released("left"):
			$AnimationPlayer.play("Idle_side");
	
	
	if Input.is_action_pressed('down'):
		velocity.y += 1
		$AnimationPlayer.play("Walk_down")
	else:
		if Input.is_action_just_released("down"):
			$AnimationPlayer.play("Idle_down");
	
	
	if Input.is_action_pressed('up'):
		velocity.y -= 1
		$AnimationPlayer.play("Walk_up")
	else:
		if Input.is_action_just_released("up"):
			$AnimationPlayer.play("Idle_up");
	
	
	
	
	if Input.is_action_pressed('right') and Input.is_action_pressed('down'):
		$AnimationPlayer.play("Walk_diag_down")
	
	if Input.is_action_pressed('left') and Input.is_action_pressed('down'):
		$AnimationPlayer.play("Walk_diag_down")
	
	if Input.is_action_pressed('right') and Input.is_action_pressed('up'):
		$AnimationPlayer.play("Walk_diag_up")
	
	if Input.is_action_pressed('left') and Input.is_action_pressed('up'):
		$AnimationPlayer.play("Walk_diag_up")

sorry if there's any bad english btw.

I think you should rearrange your code. Separate your animation code from the code that determines your velocity, and change the animation based on the velocity after you determine it.