0 votes

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:
        return

    var velocity = move_and_slide(direction_vector.normalized() * speed)
    if velocity.x > velocity.y && velocity.x < -velocity.y:
        animationPlayer.play("back_walk")
    elif velocity.x < velocity.y && velocity.x > -velocity.y:
            animationPlayer.play("front_walk")
    else:
        animationPlayer.play("side_walk")
        sprite.flip_h = velocity.x < 0
    if velocity.x == 0 && velocity.y == 0:
        animationPlayer.play("side_idle")
    print("velocity.x equals", velocity.x)
    print("velocity.y equals", velocity.y)

```

Godot version Godot 3.2.2
in Engine by (12 points)

1 Answer

–1 vote
if movement.x == 0 and movement.y == 0:
    AnimationPlayer.play("idle")
by (254 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.