animated sprite stuck in the default animation

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

i’ve started using godot a few days ago and i’m currently trying to get a character to play animations when it moves, however it just sticks with the default animation and ignores the whole script
here is the script i’m using:
onready var anim = $AnimatedSprite
func manage_animations ():
if vel.x > 0 :
play_animation(“MoveRight”)
elif vel.x < 0:
play_animation(“MoveLeft”)
elif vel.y < 0 and facingDir.x == 1:
play_animation(“MoveRight”)
elif vel.y > 0 and facingDir.x == 1:
play_animation(“MoveRight”)
elif facingDir.x == 1:
play_animation(“IdleRight”)
elif facingDir.x == -1 :
play_animation(“IdleLeft”)
elif vel.y < 0 and facingDir.x == -1:
play_animation(“MoveLeft”)
elif vel.y > 0 and facingDir.x == -1:
play_animation(“MoveLeft”)

func play_animation (anim_name):
if anim.animation != anim_name:
anim.play(anim_name)

:bust_in_silhouette: Reply From: umma
 if vel.x > 0:
   anim.play("Move_Right")

still doesn’t work, but thanks

gm130993 | 2022-01-29 21:41

are those functions working? you fing out by writing print(“it’s working”) under them ie

func manageanimations ():
 print("working") #if it doesn't print anything it isn't working

umma | 2022-01-30 03:34

i redid your script, try it now, if it doesn’t work i don’t know the problem. Ensure that it is printing something, also if it shows if the code shows error, make sure to remove any space

onready var anim = $AnimatedSprite

func _process(delta):
 _manage_animations()

func _manage_animations():
 print("ggggggggggg")
 if vel.x > 0 :
  anim.play("MoveRight")
 elif vel.x < 0:
  anim.play("MoveLeft")
 elif vel.y < 0 and facingDir.x == 1:
  anim.play("MoveRight")
 elif vel.y > 0 and facingDir.x == 1:
  anim.play("MoveRight")
 elif facingDir.x == 1:
  anim.play("IdleRight")
 elif facingDir.x == -1 :
  anim.play("IdleLeft")
 elif vel.y < 0 and facingDir.x == -1:
  anim.play("MoveLeft")
 elif vel.y > 0 and facingDir.x == -1:
  anim.play("MoveLeft")

func playanimation (animname):
  print("bbbbbbbbbbbbbbb)
  if anim.animation != animname:
   anim.play(animname)

umma | 2022-01-30 03:45