Top Down Movement With 2 Direction Animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dev_cons

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")
:bust_in_silhouette: Reply From: unkownzero
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


thankyou very much

dev_cons | 2021-08-22 01:39