0 votes

So im trying to get the animation working for my top down movement but i only have the run right and left animation and i cant seem to figure out how to program my player, so when my player is facing right and then goes up i want him to keep facing right and vice versa. i also cant figure out how to deal with the idle animation.. btw im using the animated sprite node...

this is the code btw. sorry if its so messy

func get_animation():
if velocity.x > 0 or velocity.x > 0 and velocity.y < 0 or velocity.y < 0:
    animatedSprite.play("RunRight")
    if velocity == Vector2.ZERO:
        animatedSprite.play("IdleRight")
if velocity.x < 0 or velocity.x < 0 and velocity.y > 0 or velocity.y > 0:
    animatedSprite.play("RunLeft")
    if velocity == Vector2.ZERO:
        animatedSprite.play("IdleLeft")
Godot version latest
in Engine by (19 points)
edited by

1 Answer

+1 vote
Best answer
if velocity==vector2.ZERO:
    animatedSprite.play("IdleRight")
else:
    animatedSprite.play("RunRight")
    if velocity.x!=0:
       animatedSprite.scale.x=sign(velocity.x)

i think this will work


by (80 points)
selected by

thankyou very much

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.