0 votes

So I have created a cutout walking animation. And I have coded it to play when the character moves right. The problem is the character moves before the animation plays and the animation won't play unless the movement stops.

This is the code. (Not the full code. I can paste full code if you want but I thought that was unnecessary)

func _process(delta):
    velocity=Vector2()

    if Input.is_action_pressed("ui_right"):
        $Animations_Character.play("Walk")
        velocity.x +=1

Animations_Character is the Animationplayer node

in Engine by (202 points)

Found the solution I think. It's working.

func _process(delta):
velocity=Vector2()

if Input.is_action_pressed("ui_right"):
    if ($Animations_Character.current_animation!="Walk"):
        $Animations_Character.play("Walk")
    velocity.x +=1

1 Answer

+2 votes
Best answer

The problem is that you are restarting the animation all the time while the action is pressed, you want to play it only once.

There are many ways to check that, one way can be checking if the animation playing is not the movement one, if it is not, play it.

Like:

if Animations_Character.current_animation != "Walk":
  Animations_Character.play("Walk")

The platformer demos have a more complex animation setup, separated from the motions, it stores the current animation name to decide finally if play it or not, leaving "idle" as default.

by (7,908 points)
selected by
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.