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.
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:
elif velocity.x < velocity.y && velocity.x > -velocity.y:
sprite.flip_h = velocity.x < 0
if velocity.x == 0 && velocity.y == 0:
print("velocity.x equals", velocity.x)
print("velocity.y equals", velocity.y)