Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Non Convex Mesh Collider Distance Check

Discussion in 'Physics' started by Techmologue, Mar 14, 2019.

  1. Techmologue

    Techmologue

    Joined:
    Nov 21, 2017
    Posts:
    41
    Hello

    I am standing in front of a problem.
    I understand how to check distance between one object and the target Convex Mesh Collider... but how do I check the distance of one object and the other when the object I am looking for is Non Convex?

    To clarify this, I am not looking for origin to origin distance.

    I have seen a few things on Stack-Overflow which are related but they all don't work for Non Convex Mesh
    I'd appreciate any hints.

    Thank you and have a good day
     
  2. imtehQ

    imtehQ

    Joined:
    Feb 18, 2013
    Posts:
    232
    I know one way of doing this but it is not performance friendly.You can check distance between the mesh verters.
    By going trough the entire list and checking distance for each one, then get the closest one as the distance to what your looking for.
    But having like a high detailed mesh this will not do.
    There are are few ways of improving this, so the cost is a bit lower.

    But this way you will know the distance between a point and the mesh model.
    Is that what your looking for or im a completely off ?
     
    Techmologue likes this.
  3. Techmologue

    Techmologue

    Joined:
    Nov 21, 2017
    Posts:
    41
    You are spot on...
    but as you have established...
    wait a minute... I can split my race-track-collider mesh into smaller sections decreasing the count checking every smaller section ... kinda using a combination of checking the origin closest first and then checking the mesh to that race-track segment/object! Done deal ^^
    Thank you, problem solved!
     
  4. imtehQ

    imtehQ

    Joined:
    Feb 18, 2013
    Posts:
    232
    You can also store the vectors in a array first, for each section, making sure there are no doubles in it. That will make the amount of points you need to check a bit less to.

    It will be best to make it so you create those points in the editor and not at runtime, because making those arrays can cause some lagg and garbage.

    also: https://www.emanueleferonato.com/2010/07/29/the-fastest-way-to-find-the-distance-between-two-points/
     
    Techmologue likes this.