Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to compare 2 individual colliders?

Discussion in 'Physics for ECS' started by Brammel, Apr 20, 2020.

  1. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Hi,

    In the documentation it notes:
    Queries can be performed against individual colliders or against an entire collision world

    I can find ample examples of how to check vs the world.
    But how do u check 2 individual colliders?
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Each collider has its own implementation of queries. For example, take BoxCollider. You have CalculateDistance or ColliderCast which take some query input structs to which you can provide another collider and simply do a query on those two. You also have CalculateDistance from a point, and CastRay if you wish to raycast against a collider.

    Is that what you were looking for? I know we need to add examples of this, the same we have for queries against the whole world, but we just never got to it.
     
    steveeHavok likes this.
  3. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Not entirely

    i have a job like so:

    entities.foreach(in physicscollider body, in target t)
    {
    var t = getcomponent<physicscollider>(t.value);
    // now i want if (t.intersectswith(body))

    //(i currently do this by checking vs the world, and then filtering the hitlist by t's entity)
    }
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    So instead of
    physicsWorld.CalculateDistance
    , you can call
    body.Value.Value.CalculateDistance
    .
    Just be careful about the Start and End values for the distance input struct as this query in is 'body''s space rather than the worlds.
     
  5. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Am i correct in assuming that in order to check if they "currently" overlap (this frame) i should set the maxdistance to 0?
    And the transform property?
     
  6. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yes, use MaxDistance = 0 for current overlaps.