2024-12-06 10:44:53 -08:00
extends Camera3D
@export var rail : Path3D
@export var target : Node3D
2024-12-11 15:02:50 -08:00
@export var seek_easing : float = 1.0
var crv : Curve3D
var cur_offset : float
var tgt_offset : float
2024-12-06 10:44:53 -08:00
var target_pos
2024-12-11 15:02:50 -08:00
2024-12-06 10:44:53 -08:00
# Called when the node enters the scene tree for the first time.
func init ():
2024-12-11 15:02:50 -08:00
crv = rail . curve
2024-12-06 10:44:53 -08:00
target_pos = target . position
2024-12-11 15:02:50 -08:00
tgt_offset = crv . get_closest_offset ( target . position )
2024-12-06 10:44:53 -08:00
func seek_target ():
if target_pos != target . position :
2024-12-11 15:02:50 -08:00
target_pos = target_pos . move_toward ( target . position , target . position . distance_to ( target_pos ) / seek_easing ) # distancia entre los puntos dividido entre easing
2024-12-06 10:44:53 -08:00
look_at ( target_pos + Vector3 ( 0.0 , 0.70 , 0.0 ) )
func constraint_to_rail ():
2024-12-11 15:02:50 -08:00
tgt_offset = crv . get_closest_offset ( target . position )
cur_offset = move_toward ( cur_offset , tgt_offset , abs ( tgt_offset - cur_offset ) / ( seek_easing * 100 ) )
print (( tgt_offset - cur_offset ))
position = crv . sample_baked ( cur_offset )
2024-12-06 10:44:53 -08:00
func _ready ():
init ()
func _process ( delta ):
constraint_to_rail ()
seek_target ()