38 lines
1.1 KiB
GDScript
38 lines
1.1 KiB
GDScript
extends Spatial
|
|
|
|
var elevator_tracker = null
|
|
var locked = false
|
|
|
|
func _on_Area_area_entered(area: Node):
|
|
print(area)
|
|
if area.name != "ElevatorGrip" or elevator_tracker != null:
|
|
return
|
|
elevator_tracker = area.get_parent()
|
|
$"../".set_physics_node(self)
|
|
elevator_tracker.connect("arrived", self, "on_elevator_arrived", [], CONNECT_ONESHOT)
|
|
elevator_tracker.toggle()
|
|
|
|
func on_elevator_arrived():
|
|
disconnect_passenger()
|
|
|
|
func _on_Area_area_exited(area: Node):
|
|
if area.name != "ElevatorGrip" or elevator_tracker == null:
|
|
return
|
|
|
|
|
|
func disconnect_passenger():
|
|
elevator_tracker = null
|
|
$"../".set_physics_node($"../OnFootPhysics")
|
|
|
|
func _process(delta):
|
|
if elevator_tracker == null:
|
|
global_transform.origin = $"../OnFootPhysics".global_transform.origin
|
|
locked = false
|
|
return
|
|
|
|
global_transform.origin = lerp(global_transform.origin, elevator_tracker.global_transform.origin, delta*10)
|
|
|
|
if locked or (global_transform.origin - elevator_tracker.global_transform.origin).length() < 0.05:
|
|
locked = true
|
|
global_transform.origin = elevator_tracker.global_transform.origin
|