extends CharacterBody2D class_name Player @export var speed = 400 func get_input(): calculate_direction() if Input.is_action_just_pressed("interact"): try_interact() func calculate_direction(): var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down") velocity = input_direction * speed if input_direction.x: $Sprite.flip_h = (input_direction.x < 0) func try_interact(): var interactables : Array[Interactable] for area2D in $InteractArea2D.get_overlapping_areas(): if area2D is Interactable: interactables.push_front(area2D) if len(interactables): if len(interactables) > 1: # Sort them to the closer interactables.sort_custom( func (el1 : Interactable, el2 : Interactable): return el1.global_position.distance_to(global_position) > el2.global_position.distance_to(global_position) ) interactables[0].interact(self) func _physics_process(_delta): get_input() move_and_slide()