extends CharacterBody2D @export var SPEED = 100.0 @onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D func _physics_process(_delta: float) -> void: # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var direction := Vector2(Input.get_axis("left", "right"), Input.get_axis("up", "down")) if direction: velocity = direction * SPEED if direction.x != 0: animated_sprite_2d.flip_h = direction.x >= 0 animated_sprite_2d.play("default") else: animated_sprite_2d.play("idle") velocity.x = move_toward(velocity.x, 0, SPEED) velocity.y = move_toward(velocity.y, 0, SPEED) move_and_slide()