52 lines
1.2 KiB
GDScript
52 lines
1.2 KiB
GDScript
extends Tile
|
|
class_name TileTurn
|
|
|
|
@onready var area_3d = $Area3D as Area3D
|
|
@onready var path_forward = $PathForward as Path3D
|
|
@onready var path_right = $PathRight as Path3D
|
|
@onready var path_left = $PathLeft as Path3D
|
|
|
|
var connected = false
|
|
var current_direction = "forward"
|
|
var on_main_path = true
|
|
|
|
|
|
func _ready():
|
|
paths.append($MainPath)
|
|
paths.append($PathForward)
|
|
|
|
|
|
func _process(delta):
|
|
for area in area_3d.get_overlapping_areas():
|
|
if area is Character and not connected:
|
|
var character = area as Character
|
|
character.turn.connect(turn)
|
|
connected = true
|
|
super(delta)
|
|
|
|
|
|
func turn(direction):
|
|
if on_main_path:
|
|
current_direction = direction
|
|
paths[path_index+1] = get_path_by_direction(current_direction)
|
|
|
|
|
|
#func has_next_path() -> bool:
|
|
#return on_main_path
|
|
|
|
|
|
#func get_next_path() -> Path3D:
|
|
#if not on_main_path:
|
|
#return get_path_by_direction(current_direction)
|
|
#return null
|
|
|
|
|
|
func get_path_by_direction(direction) -> Path3D:
|
|
if direction == "forward" and path_forward != null:
|
|
return path_forward
|
|
elif direction == "right" and path_right != null:
|
|
return path_right
|
|
elif direction == "left" and path_left != null:
|
|
return path_left
|
|
return null
|