FantasyRun/world.gd
Matthew Welch 7819007b01 Add initial tile scenes
Update script to dynamically find paths to follow
2024-09-27 16:49:56 -07:00

30 lines
817 B
GDScript

extends Node3D
@onready var path: Path3D = $Path
@onready var marker: Marker3D = $Path/Follow/Marker
@onready var character: Character = $Character
var change_distance: float
var paths: Array
var current_path: int = 0
func _ready() -> void:
paths = Utils.get_nodes_of_class(self, Path3D)
if paths.size() == 0:
printerr("There are no Path3Ds in the scene.")
return
change_distance = paths[current_path].curve.get_baked_length()
if character.path == null:
character.path = paths[current_path]
func _process(delta: float) -> void:
if is_equal_approx(character.follow.progress, change_distance):
current_path += 1
if current_path >= paths.size():
return
marker.reparent(paths[current_path])
character.path = paths[current_path]
change_distance = paths[current_path].curve.get_baked_length()