37 lines
1.1 KiB
GDScript
37 lines
1.1 KiB
GDScript
extends Node3D
|
|
|
|
const DOOR_OPEN_X := 1.154
|
|
const DOOR_CLOSED_X := 0.7
|
|
const DOOR_DEFAULT_TIME := 3.0
|
|
const DOOR_FAST_CLOSE_TIME := 1.0
|
|
const DOOR_REOPEN_TIME := 0.4
|
|
|
|
var _tween: Tween = null
|
|
|
|
func _ready():
|
|
$ElevatorDoorRight.position = Vector3(DOOR_CLOSED_X, 0, 0)
|
|
$ElevatorDoorLeft.position = Vector3(-DOOR_CLOSED_X, 0, 0)
|
|
EventBus.doors_opened.connect(_on_doors_opened)
|
|
EventBus.doors_closed.connect(_on_doors_closed)
|
|
EventBus.pulse_started.connect(_on_pulse_started)
|
|
EventBus.pulse_blocked.connect(_on_pulse_blocked)
|
|
|
|
func _on_doors_opened():
|
|
_tween_doors(DOOR_OPEN_X, DOOR_DEFAULT_TIME)
|
|
|
|
func _on_doors_closed(fast: bool):
|
|
_tween_doors(DOOR_CLOSED_X, DOOR_FAST_CLOSE_TIME if fast else DOOR_DEFAULT_TIME)
|
|
|
|
func _on_pulse_started(duration: float):
|
|
_tween_doors(DOOR_CLOSED_X, duration)
|
|
|
|
func _on_pulse_blocked():
|
|
_tween_doors(DOOR_OPEN_X, DOOR_REOPEN_TIME)
|
|
|
|
func _tween_doors(target_x: float, duration: float):
|
|
if _tween:
|
|
_tween.kill()
|
|
_tween = create_tween()
|
|
_tween.set_parallel(true)
|
|
_tween.tween_property($ElevatorDoorRight, "position:x", target_x, duration)
|
|
_tween.tween_property($ElevatorDoorLeft, "position:x", -target_x, duration)
|