Sprite Animation not playing in animatedsprite3d node

Godot Version

Godot v.4.2

Question

Hello I am new to Godot, and have a question I haven’t been able to find the answers to. I am using the AnimatedSprite3D node to make a character move in simple 3d space. However, when I move the character, on the first frame of the animation plays when I walk in any of the four(ish) directions. i followed the documentation for the 2d animated sprite because to me it was saying is the same for 3d. I know it is somewhat recognizing the sprite3d node because when I comment out my method for changing the animation I don’t even get the first frame and its a static sprite for all directions.

Here is my code in the character body 3d node script, with the animatedsprite3d as its child, in a func _process(delta)

# Move left
if Input.is_action_pressed("move_left"):
	_animated_sprite.play("WalkLeft")
else:
	_animated_sprite.stop()
	
# Move Right
if Input.is_action_pressed("move_right"):
	_animated_sprite.play("WalkRight")
else:
	_animated_sprite.stop()
# Move Down
if Input.is_action_pressed("move_forward"):
	_animated_sprite.play("WalkUp")
else:
	_animated_sprite.stop()
	
# Move Up
if Input.is_action_pressed("move_backward"):
	_animated_sprite.play("WalkDown")
else:
	_animated_sprite.stop()

Hi, the issue is that you have four separate if statements. If you press “move_left”, it will play the “WalkLeft” animation. However, in the same frame, you are not pressing “move_right”, “move_forward”, and “move_backwards”, all of which will stop the animation from playing. I suggest using Input.get_vector() to get a vector of all four actions and only stopping the animation if the length of that vector is 0 (using Vector2.is_zero_approx()).

Oh that makes a lot of sense, thank you! I will try this and see how it goes

this is my new code. it works perfectly! thanks @shatteredreality

if Input.is_action_pressed("move_left") and not input_dir.is_zero_approx():
	_animated_sprite.play("WalkLeft")
elif Input.is_action_pressed("move_right")and not input_dir.is_zero_approx():
	_animated_sprite.play("WalkRight")
elif Input.is_action_pressed("move_forward")and not input_dir.is_zero_approx():
	_animated_sprite.play("WalkUp")
elif Input.is_action_pressed("move_backward")and not input_dir.is_zero_approx():
	_animated_sprite.play("WalkDown")
elif input_dir.is_zero_approx():
	_animated_sprite.stop()