xxxxxxxxxx
func get_enemy():
var closest_enemy = null
var shortest_distance = INF
for enemy in get_tree().get_nodes_in_group("enemies"):
if not is_instance_valid(enemy):
continue
var distance = position.distance_to(enemy.position)
if distance < shortest_distance:
shortest_distance = distance
closest_enemy = enemy
return closest_enemy
func generate_path():
var enemy = get_enemy()
if levelNav != null and is_instance_valid(enemy):
return levelNav.get_simple_path(position, enemy.position)
return Array()