How to play animation correctly when getting diagonal movement inputs?

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

Hi! Still new to gamedev.

Script is attached to a KinematicBody2D ($Player) node. There are three animations in a $Body animated sprite: “Move”, “Move Away”, and “Idle”. 8-dir movement works fine and mostly animating as intended.
Issue is when the Player moves away from the cursor in a diagonal direction. When moving in this specific direction in relation to the cursor, animation is stuck on the first frame of the “Move Away” animation.

I’ve tried combinations of if statements (messy, I know) but with no luck. Maybe I’m not accounting for the velocity or normalization in the methods? Can anyone tell me what I’m missing or have incorrect? Thanks!

func get_movement_input():
	velocity = Vector2()
	if Input.is_action_pressed('ui_down'):
		velocity.y += 1
		$Body.play("Move")
	if Input.is_action_pressed('ui_up'):
		velocity.y -= 1
		$Body.play("Move")
	if Input.is_action_pressed('ui_right'):
		velocity.x += 1
		if global_position.x < get_global_mouse_position().x:
			$Body.play("Move")
		if global_position.x > get_global_mouse_position().x:
			$Body.play("Move Away")
	if Input.is_action_pressed('ui_left'):
		velocity.x -= 1
		if global_position.x > get_global_mouse_position().x:
			$Body.play("Move")
		if global_position.x < get_global_mouse_position().x:
			$Body.play("Move Away")
	if velocity == Vector2(0, 0): # Cannot be 'else' or the other three inputs before 'ui_up' would be overriden
		$Body.play("Idle")
	velocity = velocity.normalized() * speed