How to determine closest visible actor in linetrace view?

I’m creating an enemy ai system and I want to figure out how to determine which player is closest, but also visible to see, to chase. Right now my code only gets the closest player (no matter if there is a wall or not) and sticks with it permanently It (In the picture example, it would think only the player on the bottom right exists and chase once their visible. Any ideas on how to fix? Would really appreciate it. (Custom event linked to a Set Timer By Function Name)

My current code

Result

Thanks for clicking.

You don’t seem to be updating location nearest distance each time you find another actor which is closer than the current one. Also if you want to keep searching for the nearest actor you should set it to a very high number each time the loop starts.

2 Likes

Oh wow how did I not see that!? Thank you so much for pointing that out. Works nicely now.

1 Like