2024-02-22 19:52:10 +00:00
|
|
|
extends Node3D
|
|
|
|
|
2024-02-23 12:09:40 +00:00
|
|
|
@export var target: Node3D
|
2024-02-22 19:52:10 +00:00
|
|
|
var currTransform: Transform3D
|
|
|
|
var prevTransform: Transform3D
|
|
|
|
|
2024-02-23 12:09:40 +00:00
|
|
|
|
2024-02-22 19:52:10 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
|
|
|
currTransform = Transform3D()
|
|
|
|
prevTransform = Transform3D()
|
|
|
|
set_process_priority(100)
|
|
|
|
set_as_top_level(true)
|
|
|
|
Engine.set_physics_jitter_fix(0.0)
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
if target == null:
|
|
|
|
return
|
|
|
|
var f := Engine.get_physics_interpolation_fraction()
|
|
|
|
var new_transform: Transform3D = Transform3D()
|
|
|
|
|
|
|
|
var ptDiff := currTransform.origin - prevTransform.origin
|
|
|
|
new_transform.origin = prevTransform.origin + (ptDiff * f)
|
|
|
|
new_transform.basis = _LerpBasis(prevTransform.basis, currTransform.basis, f)
|
|
|
|
|
|
|
|
transform = new_transform
|
|
|
|
|
2024-02-23 12:09:40 +00:00
|
|
|
|
2024-02-22 19:52:10 +00:00
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
prevTransform = currTransform
|
|
|
|
currTransform = target.global_transform
|
|
|
|
|
|
|
|
|
|
|
|
func _LerpBasis(from: Basis, to: Basis, f: float) -> Basis:
|
|
|
|
var res: Basis = Basis()
|
|
|
|
res.x = from.x.lerp(to.x, f)
|
|
|
|
res.y = from.y.lerp(to.y, f)
|
|
|
|
res.z = from.z.lerp(to.z, f)
|
|
|
|
return res
|