My solution to the challenge was to put the distance check before the progress check, because I thought: let’s first see if the enemy is in range and then find out which one is closet to the base.
Is there a difference that I’m overlooking or are both solutions fine?
This is my code:
func find_best_target() -> PathFollow3D:
var best_target = null
var best_progress = 0
for enemy in enemy_path.get_children():
if enemy is PathFollow3D:
var distance = global_position.distance_to(enemy.global_position)
if distance < turrent_range:
if enemy.progress > best_progress:
best_target = enemy
best_progress = enemy.progress
return best_target