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 josessito · Apr 16, 2014 at 11:27 PM · colliderobjectpointsearchclosest

Find closest point of one object

That is basically it. I need to find the closest point in one object's mesh or collider, to another one (or: the closest point of a mesh to a second point in a certain radius).

alt text

I have tried some approaches but fail. I tried creating a "trigger" CirlceCollider, then get the collisions with other colliders, but that only gives me the points were the colliders intersect. There may be simple way to do this but I've search and think for two days and I just can't figure this one out. Any help would be very appreciated.

EDIT: Re-uploaded the image.

point.png (101.5 kB)
Comment
Add comment · Show 6
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 robertbu · Apr 16, 2014 at 11:28 PM 0
Share

You picture link is broken.

avatar image jonSG · Apr 16, 2014 at 11:44 PM 0
Share

If your objects are fairly regular like your picture then the midpoint between points of intersection might be a good approximation. You might cast a ray at that point and find where it collides with you object.

avatar image josessito · Apr 16, 2014 at 11:50 PM 0
Share

@jonSG: Yes, that was my reasoning too, but it I was hopping maybe there was a better approach... Thanks anyway.

avatar image robertbu · Apr 17, 2014 at 12:33 AM 0
Share

If this is something you are going to be doing over and over, your mesh is pretty detailed, and if you can live with an approximation, you could take the vertices of the mesh and convert them to world space points. Then you could just run through the array and compare your position to these points.

avatar image Benproductions1 · Apr 17, 2014 at 03:38 AM 0
Share

Expanding on @robertbu's comment, if you want a perfect solution, find the closest point between the closest points of every line-segment that makes up both meshes. Would be quite expensive though.

Show more comments

3 Replies

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

Answer by Lofar42 · Nov 30, 2015 at 06:40 PM

Hey, I realise this is over a year old now so I don't expect I'm adding anything of use really, but I was looking for an answer to the same question and eventually came across this:

http://docs.unity3d.com/ScriptReference/Collider.ClosestPointOnBounds.html

This should give you a point on the bounding box, which you could then raycast towards to find the actual hit position. Still wouldn't be EXACTLY accurate but would be a closer approximation I think.

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

Answer by rathoddhaval · Apr 17, 2014 at 04:04 AM

Answer Is In Your Question Where U draw Circle. In Unity Using Physics.SphereCastAll Returns All The RaycastHit In Array From(RaycastHit[] array) That You Can Find Min Distance Hit Point.

Like Example

RaycastHit GetMinDistancePoint() { RaycastHit[] points = Physics.SphereCastAll(transform.position, 10, transform.forward); float minDist = 100; RaycastHit selectionPoint; foreach (RaycastHit hit in points) { if (hit.distance < minDist) { minDist = hit.distance; selectionPoint = hit; } } return selectionPoint; }

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 Benproductions1 · Apr 17, 2014 at 04:39 AM 1
Share
  1. format your code

  2. read the question, that's not what it's asking

avatar image
0

Answer by matbb · May 03, 2020 at 10:43 AM

Had the same question years after the question, came here, my updated answers (2020) are below.

Use "Physics.ClosestPoint" (gives closest point on a colider as asked in the question) or in some cases "Physics.ComputePenetration" and find the location from the penetration direction, while making the first object a small sphere.

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

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

25 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

Related Questions

Collider added far from object 1 Answer

Need some help an object collider that stops a timer then displays it on another scene 1 Answer

How do I display the objects collider box in a running scene 2 Answers

Why can't compiler find Physics.ClosestPoint or Collider.ClosestPoint? 1 Answer

Closest object from player relative to swipe direction 0 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