extends Tile class_name TileTurn enum Direction { Forward, Left, Right, Both } @export var turn_direction: Direction = Direction.Forward @onready var area_3d: Area3D = $Area3D as Area3D @onready var path_forward: TilePath = $PathForward as TilePath @onready var path_right: TilePath = $PathRight as TilePath @onready var path_left: TilePath = $PathLeft as TilePath var connected: bool = false var current_direction: Direction = Direction.Forward var character: Character var on_main_path: bool: get: return path_index == 0 func _process(delta: float) -> void: var character_found = false for area in area_3d.get_overlapping_areas(): if area is Character: character_found = true if connected: break character = area as Character character.turn.connect(turn) connected = true if not character_found and connected: character.turn.disconnect(turn) connected = false super(delta) func load_path() -> void: paths.append($MainPath) paths.append($PathForward) func turn(direction: Direction) -> void: if on_main_path: var next_path: TilePath = get_path_by_direction(direction) if next_path == null or (direction != turn_direction and direction != Direction.Both): return current_direction = direction paths[path_index+1] = next_path func get_path_by_direction(direction: Direction) -> TilePath: if direction == Direction.Forward and path_forward != null: return path_forward elif direction == Direction.Right and path_right != null: return path_right elif direction == Direction.Left and path_left != null: return path_left return null