class_name PlayerController extends Controller ## The character that we're controlling. var player: Player ## We need the movement component to check if we can perform certain actions. var movement: MovementComponent func _init(new_player: Player): player = new_player movement = player.find_child("Movement") func _unhandled_input(event): if Global.interacting_with_ui: return # Calculate the direction var move := Input.get_vector("move_left", "move_right", "move_forward", "move_backward") var direction := (Global.camera.global_basis * Vector3(move.x, 0, move.y)) direction.y = 0 direction = direction.normalized() # Notify components player.set_direction(direction) if event.is_action_pressed("jump") && movement && movement.can_jump(): player.jump() if event.is_action_pressed("dash"): player.dash() for i in range(4): if event.is_action_pressed("skill_%d" % (i + 1)): player.use_skill(i)