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
2
Question by CommitteeWind · Nov 13, 2010 at 09:37 PM · rtsselectionaccuracy

Accurate RTS Selection

OK so I've been using the following code to do my RTS style selection:

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    Physics.Raycast(ray, out info);

If the camera is down (90, 0, 0) the accuracy of my selection box is 100%. However, the more I rotate the camera, the more depth inaccuracies occur. For instance, the way my selection box works is:

1) At the start of drag record an initial point in space via the above code.
2) At the end of drag record an ending point in the space via the above code.
3) Iterate through the game objects to see which ones reside within the rectangle.

Note: The rectangle is definitely working properly; it is in world space and not screen space.

alt text

So, that's what happens. It seems to me that the depth of the clicks are not right.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Eric5h5 · Nov 13, 2010 at 11:18 PM

Instead of trying to use a world-space selection box like that, see if the objects' coordinates when converted to screen space are within the screen-space rectangle instead.

Edit: indeed this method does only test for the object's pivot, but I think you actually want that; certainly it's typical in games (the bottom two here aren't selected in case it's not obvious):

alt text

Comment
Add comment · Show 2 · 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 Ashkan_gc · Apr 28, 2011 at 05:38 PM 0
Share

it has it's own drawbakcs too. because sometimes pivots of objects are out of the rectangle but a big part of them is inside however it's a good solution.

avatar image Eric5h5 · Apr 28, 2011 at 08:53 PM 0
Share

@Ashkan: true, but I'm not sure that's actually a drawback, or at least it seems natural, maybe because that's what other games do. See my edit.

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

No one has followed this question yet.

Related Questions

Create selection box by double tapping then dragging? (android mobile)(cnc style)(image embedded) 1 Answer

Math/Programming Question 4 Answers

Cant select objects using my box-selection script 1 Answer

Unity RayCast Selection 1 Answer

Avoid iterating through all gameobjects to select units using marquee selection box (selection box is already created, just have to be efficient) 2 Answers


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