FantasyRun/world.gd

33 lines
947 B
GDScript3
Raw Normal View History

extends Node3D
@export var speed: float = 10
@onready var path_3d_2: Path3D = $Path3D2
@onready var path: Path3D = $Path
@onready var follow: PathFollow3D = $Path/Follow
@onready var marker: Marker3D = $Path/Follow/Marker
var points_added = false
var point_removed = false
var change_distance: float
var total_distance: float = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
change_distance = path.curve.get_baked_length()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
%Character.global_position = marker.global_position
if follow.progress_ratio >= 1:
return
var travel = speed * delta
follow.progress += travel
total_distance += travel
if is_equal_approx(follow.progress, change_distance):
path = $Path3D2
follow = path.get_node(("Follow"))
change_distance = path.curve.get_baked_length()
marker.reparent(follow)