I can't get the left and right animations to work

Godot Version

4.2,1

Question

after a good while of messing around with it, i eventualy got the up and down animations to work, but i still can’t figure out what is wrong with the left and right animations.

func _process(delta):
		#animation controll
	while velocity <= Vector2(-0.001, 0):
		AnimetedSprite2D.play("walk left")
		break
			#animation controll
	while  velocity >= Vector2(0.001, 0):
		AnimetedSprite2D.play("walk right")
		break
		#animation controll
	while  velocity <= Vector2(0, 0.001):
		AnimetedSprite2D.play("walk up")
		break
		#animation controll
	while  velocity >= Vector2(0, -0.001):
		AnimetedSprite2D.play("walk down")
		break
	

Hi!
Not sure how this is working at all since there is a spelling error in animated sprite :slight_smile:
You can use the x and y dimension to simply check for horizontal and vertical movement, comparing the components separately and without the loop.

func _process(delta):
    # Animation control
    if velocity.x < -0.001:
        AnimatedSprite2D.play("walk left")
    elif velocity.x > 0.001:
        AnimatedSprite2D.play("walk right")
    elif velocity.y < -0.001:
        AnimatedSprite2D.play("walk up")
    elif velocity.y > 0.001:
        AnimatedSprite2D.play("walk down")
    else:
        AnimatedSprite2D.stop()

Didn’t test the code though.

1 Like

Oh my goodness, thank you so much. I forgot that whole velocity.x and y thing existed!