meat_madness_redux/godot/player/ElevatorPhysics.gd

38 lines
1.1 KiB
GDScript3
Raw Normal View History

2022-11-27 13:31:09 -07:00
extends Spatial
var elevator_tracker = null
2022-11-27 17:25:59 -07:00
var locked = false
2022-11-27 13:31:09 -07:00
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")
2022-11-27 17:25:59 -07:00
func _process(delta):
2022-11-27 13:31:09 -07:00
if elevator_tracker == null:
global_transform.origin = $"../OnFootPhysics".global_transform.origin
2022-11-27 17:25:59 -07:00
locked = false
2022-11-27 13:31:09 -07:00
return
2022-11-27 17:25:59 -07:00
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