I have a code for founding a closest enemy, code checks which enemy does have higher progress, body in this case are PathFollow2d
This is the code: func spot():
var enemy = $Area2D.get_overlapping_bodies()
if enemy.size() > 0:
for body in $Area2D.get_overlapping_bodies():
var telo = body.get_parent()
if telo.progress >= 0:
closest = telo
Problem with this code is that it gets the last body , or body with least progress. Thanks
I’m making a lot of assumptions about what closest is supposed to represent, I’m assuming closest is the telo with the highest progress. In this case you must only set closest = telo when the telo has a higher progress than closest, aka that if statement.