41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
extends State
|
|
|
|
class_name SitState
|
|
|
|
var reverse: bool = false
|
|
|
|
func enter() -> void:
|
|
reverse = false
|
|
super.enter()
|
|
|
|
if agent.anim_player and not agent.anim_player.animation_finished.is_connected(_on_animation_finished):
|
|
agent.anim_player.animation_finished.connect(_on_animation_finished)
|
|
|
|
if runtime_timer and not runtime_timer.is_stopped():
|
|
runtime_timer.stop()
|
|
|
|
run_animation()
|
|
|
|
func exit() -> void:
|
|
super.exit()
|
|
if agent.anim_player and agent.anim_player.animation_finished.is_connected(_on_animation_finished):
|
|
agent.anim_player.animation_finished.disconnect(_on_animation_finished)
|
|
|
|
func _on_animation_finished(anim_name: StringName) -> void:
|
|
if animation_name == anim_name:
|
|
if not reverse:
|
|
if min_wait_time > 0:
|
|
var wait_time := randf_range(min_wait_time, max_wait_time)
|
|
runtime_timer.start(wait_time)
|
|
else:
|
|
_on_timer_timeout()
|
|
else:
|
|
transitioned.emit(self, get_next_state())
|
|
|
|
func _on_timer_timeout() -> void:
|
|
reverse = true
|
|
if agent.anim_player and agent.anim_player.has_animation(animation_name):
|
|
agent.anim_player.play_backwards(animation_name, blend_time)
|
|
else:
|
|
transitioned.emit(self, get_next_state())
|