68 lines
1.9 KiB
GDScript
68 lines
1.9 KiB
GDScript
extends Spatial
|
|
var e1_hotlist = []
|
|
var e2_hotlist = []
|
|
var teleport = []
|
|
enum {DOOR_OPEN, DOOR_CLOSE}
|
|
var state = DOOR_CLOSE
|
|
|
|
func _ready():
|
|
var e = $e1.connect("body_entered", self, "e1_enter")
|
|
assert(e == OK)
|
|
e = $e1.connect("body_exited", self, "e1_exit")
|
|
assert(e == OK)
|
|
e = $e2.connect("body_entered", self, "e2_enter")
|
|
assert(e == OK)
|
|
e = $e2.connect("body_exited", self, "e2_exit")
|
|
assert(e == OK)
|
|
|
|
func e1_enter(body):
|
|
if !body.is_in_group("characters"):
|
|
return
|
|
if body in e1_hotlist:
|
|
return
|
|
var pv1 = body.global_transform.basis[2]
|
|
var pv2 = -($e2.global_transform.origin - $e1.global_transform.origin).normalized()
|
|
if (pv1 - pv2).length() > 0.8:
|
|
return
|
|
e2_hotlist.push_back(body)
|
|
if body.is_in_group("npc"):
|
|
teleport.push_back([body, $e2.global_transform.origin])
|
|
if state == DOOR_CLOSE:
|
|
if body.is_in_group("npc"):
|
|
$doorway/door/AnimationPlayer.play("door-open")
|
|
else:
|
|
$doorway/door/AnimationPlayer.play("door-openning")
|
|
state = DOOR_OPEN
|
|
else:
|
|
$doorway/door/AnimationPlayer.play("door-open")
|
|
func e1_exit(body):
|
|
if body in e1_hotlist:
|
|
e1_hotlist.erase(body)
|
|
func e2_enter(body):
|
|
if !body.is_in_group("characters"):
|
|
return
|
|
if body in e2_hotlist:
|
|
return
|
|
var pv1 = body.global_transform.basis[2]
|
|
var pv2 = -($e1.global_transform.origin - $e2.global_transform.origin).normalized()
|
|
if (pv1 - pv2).length() > 0.8:
|
|
return
|
|
e1_hotlist.push_back(body)
|
|
if body.is_in_group("npc"):
|
|
teleport.push_back([body, $e1.global_transform.origin])
|
|
if state == DOOR_CLOSE:
|
|
if body.is_in_group("npc"):
|
|
$doorway/door/AnimationPlayer.play("door-open")
|
|
else:
|
|
$doorway/door/AnimationPlayer.play("door-openning")
|
|
state = DOOR_OPEN
|
|
else:
|
|
$doorway/door/AnimationPlayer.play("door-open")
|
|
func e2_exit(body):
|
|
if body in e2_hotlist:
|
|
e2_hotlist.erase(body)
|
|
func _physics_process(_delta):
|
|
while teleport.size() > 0:
|
|
var item = teleport.pop_front()
|
|
item[0].global_transform.origin = item[1]
|