Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AlwaysSunny · Oct 07, 2012 at 08:37 PM · sortweights

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Oct 07, 2012 at 11:24 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Oct 07, 2012 at 10:37 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges