How do I make diagonal animations in top down 2D? Nothing seems to be working

func updateAnimation():
if velocity.length() == 0:
animations.stop()
else:
var direction = “Down”
if velocity.x < 0: direction = “Left”
elif velocity.x > 0: direction = “Right”
elif velocity.y < 0: direction = “Up”
elif velocity.y < 0 and velocity.x < 0: direction = “UpLeft”
elif velocity.y < 0 and velocity.x > 0: direction = “UpRight”
elif velocity.y > 0 and velocity.x < 0: direction = “DownLeft”
elif velocity.y > 0 and velocity.x > 0: direction = “DownRight”
animations.play(“walk” + direction)

elif only checks the condition and runs that block if all of the previous if and elifs were false. If you’ve already checked that x is not less than zero and not greater than zero, then none of your diagonal checks will be true either.

if you want that code to work you just need to change the first diagonal elif to an if instead

1 Like

Thank you so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.