0 votes

So my current code for animation player is "laggy" and doesn't change direction very quickly. How can I change the code so if players do spam the left and right buttons the animation player will respond accordingly? Here is the sprite sheet for reference: Sprite Sheet. My animation player is: .3 seconds with .1 steps and keyframes at 0, 1, 2, 0 for left animation and 3, 4, 5, 3 for right animation

func _fixed_process(delta):
    velocity.y += delta * GRAVITY
    if (Input.is_action_pressed("ui_left")):
        velocity.x = -WALK_SPEED
        if not animPlayer.is_playing():
            sprite.set_frame(0)
            animPlayer.play("walk_left")
    elif (Input.is_action_pressed("ui_right")):
        velocity.x = WALK_SPEED
        if not animPlayer.is_playing():
            sprite.set_frame(4)
            animPlayer.play("walk_right")

    else:
        velocity.x = 0
in Engine by (60 points)

A side comment:
If that is your spritesheet, you can have a single "walk" animation and just flip texture when turning.

1 Answer

+1 vote
Best answer

You have to check which animation is currently played. (getcurrentanimation ( ))

If your player is pressing right, while current animation is walk_left, you want to change that !

Also eventually stop the animation, and set it to its starting position when your player doesn't press any key. (or eventually start an "idle" animation)

by (340 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.