meat_madness_redux/godot/player/ElevatorPhysics.gd

31 lines
823 B
GDScript3
Raw Normal View History

2022-11-27 13:31:09 -07:00
extends Spatial
var elevator_tracker = null
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
return
global_transform.origin = elevator_tracker.global_transform.origin