Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 bol398 · Jul 11, 2017 at 06:26 PM · vectorsclosest

Getting the closest Vector3 to the mouse position

I've made a function that places vectors in a list making a grid, and I want to somehow highlight which vector or grid that is selected (When the mouse is hovering over it). I tried putting the Vectors in a list and then for each vector I would do the "if distance is less than closest, closest = distance" and than worked when I only hade a few grid but when I made the map bigger it became a problem.

I then started thinking about making like a OverlapSpherethat would get only the closest vectors and then find out which one of those vectors are the closest. But the thing is I don't know how to make the OverlapSphere only check those vectors. (I can't really make them into gameobjects due to performance on larger maps i think, not sure about that though).

If you have any other ideas please feel free to tell me. Thanks.

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

2 Replies

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

Answer by Jwizard93 · Jul 11, 2017 at 07:44 PM

You could try making a 2D array instead of list where the indexes represent the Vectors actual position in the grid. That way the mouse position would put you "inside of a box on the grid" and you would just test the four corners for the closest one.

Does that make sense?

Comment
Add comment · Show 4 · 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 bol398 · Jul 11, 2017 at 08:52 PM 0
Share

Yeah, thanks. I will probably try that tomorrow, sounds great

avatar image bol398 · Jul 12, 2017 at 04:31 AM 0
Share

Could you try to explain it a bit $$anonymous$$ore. I just realised i dont understand it

avatar image bol398 · Jul 12, 2017 at 04:33 PM 0
Share

I finally got it to work doing what you told me. Thank you!

avatar image Jwizard93 bol398 · Jul 12, 2017 at 05:13 PM 0
Share

Sorry I wasn't there to better explain earlier. But hey I can't say that I would have figured it out any faster than you. Good Job!

avatar image
1

Answer by Cornelis-de-Jager · Jul 11, 2017 at 11:29 PM

There is a InBuilt Unity Function that you might want to have a look at.

 void OnMouseEnter () {
      // Mouse is now over so change the colour/highlight object
 }
 
 void OnMouseExit () {
    // Return to default 
 }
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 bol398 · Jul 12, 2017 at 04:29 AM 0
Share

I can't see that working since that world only work on gameobjects. I could be wrong though

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

69 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

geting the closest object from a array 2 Answers

Move an object towards closest enemy. 1 Answer

Sorting an array of vectors in javascript 1 Answer

Vector math problem 2 Answers

Drag/Move an object perpendicular to starting point 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