How to find the nearest actor in a direction?

Hi everyone!

I need a little help figuring out how to find the nearest actor in a specific direction.

a little explanation:
I have a turn based system in which enemies spawn randomly around the board. when the player begins the ATTACK the enemy nearest to him automatically becomes targeted for player action, from here I want the player to be able to select the next nearest enemy to the enemy that is currently selected based on the direction that the player inputs.

I imagine something like this:

and so we check from the newly targeted enemy to see which will be targeted next when the player presses up, down, left or right again.

I’m not really looking for a full system here since I already have a lot built. I’m just wondering specifically whats in the title, how to get that one nearest actor located in the specified direction(or maybe within a specified cone?) into an array so I can use them.

Any help would be much appreciated.

Ok great thanks, except call them what you may, my question is how do I collect the actors within said triangle into and array.

Sorry for posing such a simple question I suppose, but I’m not a programmer nor do i have much experience with unreal. I figured this was the place to come for answers and help.

Hey, well i created once targeting like this, you should get all actors near you into array(multisphere trace works just fine) then you should loop throught that array and make find look at rotation to character, then compare delta rotations, to sort them by yaw. and decide to which actor yaw’s to select, also you should sort them by distance to pick the closest one and needed direction one, i hope it gives you the idea.

This is helpful. thanks!

Let’s simply call those sections “triangles”. Just collect all actors being inside the triangle you’re aiming at into an array and find the closest one. I hope I understand your question corectly, because this sounds too easy :-D.

This definitelly IS a place to came to seek help. I didn’t mean it badly. This is a simple algo that tells you whether a point lies within a triangle, though implementation of this in Blueprint will be pretty messy.

turns out it was

hello, if you are still looking for blueprint setup i can show you my logic which works just fine.

I appreciate it but i got it resolved. i just had no idea what sukovf meant at the time. I put the project on hold and i was working on something else in which i actually used the same method sukovf pointed out. and since it dawned on me that that was the answer to the question i went ahead and marked it resolved.

I would love to see that. I have a similar situation with AI controller finding cover while moving closer to their target.