Play idle animation when character is not moving

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

I’m using a script to control my player by pointing and clicking with the mouse and its walking animation keeps playing after it has reached its location when I want it to play its idle animation. I tried to tell the player to play the idle whenever the velocity is 0, but it seems that the velocity snaps to its value whenever the mouse is clicked, rather than going back down to 0 like I thought it would. .

Games with traditional arrow key control typically just tell the character to play the idle animation when no arrow keys are being pressed. Is there something similar to this in point and click control? Here’s some of the script.

if last_mouse_pos: 
	var direction_vector = (last_mouse_pos - global_position)
	if direction_vector.length() < 3:
	var velocity = move_and_slide(direction_vector.normalized() * speed)
	if velocity.x > velocity.y && velocity.x < -velocity.y:"back_walk")
	elif velocity.x < velocity.y && velocity.x > -velocity.y:"front_walk")
		sprite.flip_h = velocity.x < 0
	if velocity.x == 0 && velocity.y == 0:"side_idle")
	print("velocity.x equals", velocity.x)
	print("velocity.y equals", velocity.y)
:bust_in_silhouette: Reply From: Bot7
if movement.x == 0 and movement.y == 0:"idle")