- Home /
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?
I suppose I've settled on a solution for now, which involves using a custom struct to store an (index,score) pair. I loop through my potential targets, score them based on weighted distance & angle, then sort that list by score and use the first entry as my Best Target. Not too shabby.
Answer by Muuskii · Oct 07, 2012 at 08:57 PM
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.
Hey, I appreciate the effort, but I already have all this information. I have two lists containing the same objects. One is sorted by distance from the player, the other by screen-space angle. What I'm looking for is suggestions on how to approach making a weighted decision about which target is most likely the user's intended target, favoring (close proximity & wide angle) over (distant proximity & narrow angle). $$anonymous$$ake sense?
Your answer
Follow this Question
Related Questions
switch between multiple cameras based on distance to target 2 Answers
Sort By Distance, Call it multiple times. 2 Answers
Dynamic Turn Order and Display Based On Initiative Value (Javascript)? 2 Answers
sorting list of key, value by value 1 Answer
Animation; character weights show differently on device than in Unity. 1 Answer