cawez_puzzlebox/primitives/death/kill_cube.gd
2024-06-27 23:25:45 -04:00

37 lines
833 B
GDScript

extends Area3D
@export var death_direction = Vector3(0,-1,0)
var last_body
var timeout = 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
body_entered.connect(_on_area_entered)
body_exited.connect(_on_area_exit)
func _process(delta):
timeout -= delta
if timeout < 0.0 && last_body != null:
print ("killing! (fresh)")
last_body.death_direction = death_direction
last_body = null
func _on_area_entered(body : Node3D) -> void:
if last_body != null:
# If new body is added, then don't forget to kill the old one!
last_body.death_direction = death_direction
print("killing (old)")
last_body = body
# Half the keyboard input delay
timeout = 0.25
print("found body!")
func _on_area_exit(body : Node3D) -> void:
if body == last_body:
last_body = null
print("saved")