30 lines
757 B
GDScript
30 lines
757 B
GDScript
extends Area3D
|
|
|
|
var current_target: Node3D
|
|
|
|
signal new_target(value: Node3D)
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var candidate : Node3D
|
|
for body in get_overlapping_bodies():
|
|
if !is_instance_valid(candidate):
|
|
candidate = body
|
|
else:
|
|
if global_position.distance_to(candidate.global_position) > global_position.distance_to(body.global_position):
|
|
candidate = body
|
|
if is_instance_valid(candidate):
|
|
if candidate == current_target:
|
|
return
|
|
else:
|
|
current_target = candidate
|
|
new_target.emit(current_target)
|
|
HudSignalBus.new_weapon_target.emit(current_target)
|
|
else:
|
|
if is_instance_valid(current_target):
|
|
current_target = null
|
|
new_target.emit(current_target)
|
|
HudSignalBus.new_weapon_target.emit(current_target)
|
|
|
|
|