meat_madness_redux/godot/effects/ElevatorTracker.gd

40 lines
1.1 KiB
GDScript3
Raw Normal View History

2022-11-27 13:31:09 -07:00
extends Spatial
var at_top: bool = true
export var track_animation_name = ""
export var vertex_animation_name = ""
2022-11-27 17:25:59 -07:00
export var vertex_animation_path: NodePath
export var playback_speed: float
2022-11-27 13:31:09 -07:00
signal arrived
func _ready():
var _err = $AnimationPlayer.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
2022-11-27 17:25:59 -07:00
2022-11-27 13:31:09 -07:00
func toggle():
if at_top:
descend()
else:
ascend()
at_top = not at_top
func descend():
2023-01-03 00:11:47 -07:00
$"../Slurp".play()
2022-11-27 17:25:59 -07:00
yield(get_tree().create_timer(0.1), "timeout")
2022-11-27 13:31:09 -07:00
$AnimationPlayer.play(track_animation_name)
2022-11-27 17:25:59 -07:00
get_node(vertex_animation_path).play(vertex_animation_name)
$AnimationPlayer.playback_speed = playback_speed
get_node(vertex_animation_path).playback_speed = playback_speed
2022-11-27 13:31:09 -07:00
func ascend():
2022-11-27 17:25:59 -07:00
yield(get_tree().create_timer(0.1), "timeout")
2022-11-27 13:31:09 -07:00
$AnimationPlayer.play_backwards(track_animation_name)
2022-11-27 17:25:59 -07:00
get_node(vertex_animation_path).play_backwards(vertex_animation_name)
$AnimationPlayer.playback_speed = playback_speed
get_node(vertex_animation_path).playback_speed = playback_speed
2022-11-27 13:31:09 -07:00
func _on_AnimationPlayer_animation_finished(_anim_name):
emit_signal("arrived")