Weighted target selection for 3rd person game.

To pick targets in my 3rd person game, I get the agents/props around me sorted by distance, then, in another list, sorted by their relative relationship to my Left Stick input. In other words, if I’m pushing right on the stick, the agent most directly to my character’s right (in screen space) is first in that list.

So I have two lists containing the same GameObjects, one sorted by distance, the other by “best pick” based on screen position. Now I want to weigh the options of which target should be selected, creating an intuitive “target selection envelope”

I wanna give preference to proximity over ‘relative angle’ because this seems only natural and is observable behavior in lots of 3rd person action games. And don’t ya hate it when you take a swing at the wrong guy? I meant to hit that one, he’s right there!

Any comments on the best way to achieve this type of sorting?

Vector3.Distance to find distance.

Camera.WorldToViewportPoint To find out if a target is Left/Right/Up/Down.

Arrays or collections to hold and sort your target candidates.

Quaternion.LookRotation to find the angle from you to the target.