forked from funnymemellama/funnymemellama
56 lines
809 B
GDScript
56 lines
809 B
GDScript
extends AnimatableBody3D
|
|
|
|
|
|
@export_category('Door')
|
|
@export
|
|
var interactable: bool = true
|
|
@export
|
|
var autoclose_time: float = 0.0
|
|
|
|
|
|
@onready
|
|
var _door = $CollisionShape3D
|
|
@onready
|
|
var _anim = $AnimationPlayer
|
|
@onready
|
|
var _timer = $Timer
|
|
|
|
var _open = false
|
|
|
|
|
|
func _ready():
|
|
_anim.animation_finished.connect(_on_anim_finished)
|
|
_timer.timeout.connect(_on_close_timer)
|
|
|
|
|
|
func _do_open():
|
|
# Dont allow closing if the timer is running
|
|
if not _timer.is_stopped():
|
|
return
|
|
|
|
if not _open:
|
|
_anim.play('open')
|
|
if autoclose_time != 0.0:
|
|
_timer.start(autoclose_time)
|
|
else:
|
|
_anim.play_backwards('open')
|
|
|
|
|
|
func _on_anim_finished(anim_name):
|
|
_open = !_open
|
|
|
|
|
|
func _on_close_timer():
|
|
if _open:
|
|
_do_open()
|
|
|
|
|
|
func open():
|
|
_do_open()
|
|
|
|
|
|
func interact(other):
|
|
if not interactable:
|
|
return
|
|
|
|
_do_open()
|