0 votes

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 manageanimations ():
if vel.x > 0 :
play
animation("MoveRight")
elif vel.x < 0:
playanimation("MoveLeft")
elif vel.y < 0 and facingDir.x == 1:
play
animation("MoveRight")
elif vel.y > 0 and facingDir.x == 1:
playanimation("MoveRight")
elif facingDir.x == 1:
play
animation("IdleRight")
elif facingDir.x == -1 :
playanimation("IdleLeft")
elif vel.y < 0 and facingDir.x == -1:
play
animation("MoveLeft")
elif vel.y > 0 and facingDir.x == -1:
play_animation("MoveLeft")

func playanimation (animname):
if anim.animation != animname:
anim.play(anim
name)

Godot version 3.4.2
in Engine by (30 points)

1 Answer

+1 vote
 if vel.x > 0:
   anim.play("Move_Right")
by (443 points)

still doesn't work, but thanks

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

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)
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.