Question
How to make an animated diagonal movement in this script, do you have any suggestions? (It is not necessary to change this particular script, if you have your own script for this. I will be glad of any help!):
move_and_slide()
func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D
if dir == “right”:
anim.flip_h = false
if movement == 1:
anim.play(“Right”)
elif movement == 0:
anim.play(“Right_Idle”)
if dir == “left”:
anim.flip_h = true
if movement == 1:
anim.play(“Right”)
elif movement == 0:
anim.play(“Right_Idle”)
if dir == “down”:
anim.flip_h = true
if movement == 1:
anim.play(“Down”)
elif movement == 0:
anim.play(“Down_Idle”)
if dir == “up”:
anim.flip_h = true
if movement == 1:
anim.play(“Up”)
elif movement == 0:
anim.play(“Up_Idle”)
Assuming you have diagonal animations already, I would set conditions to play the diagonal animations based on the direction your character is currently moving.
I used this a 3d sprite plane, to switch animations based on the players rotation. However, for your case I don’t think you need rotation, just direction of movement. They key is to play the diagonal animations based on direction.