# How to make an animated diagonal movement

Version 4.2.2

### Question

How to make an animated diagonal movement in this script:
extends CharacterBody2D

const speed = 100
var current_dir = “none”

\$AnimatedSprite2D.play(“Down_Idle”)

func _physics_process(delta):
player_movement(delta)

func player_movement(delta):
if Input.get_action_strength(“right”):
play_anim(1)
current_dir = “right”
elif Input.get_action_strength(“left”):
play_anim(1)
current_dir = “left”
elif Input.get_action_strength(“down”):
play_anim(1)
current_dir = “down”
elif Input.get_action_strength(“up”):
play_anim(1)
current_dir = “up”
else:
play_anim(0)

``````var input_vector = Vector2.ZERO

input_vector.x = Input.get_action_strength("right") - Input.get_action_strength("left")
input_vector.y = Input.get_action_strength("down") - Input.get_action_strength("up")
input_vector = input_vector.normalized()

if input_vector:
velocity = input_vector * speed
else:
velocity = input_vector

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")
``````