Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Concave collider OnTriggerExit called while object inside

Discussion in 'Physics' started by Wattosan, Jun 15, 2020.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Hello,

    I have an issue where I have an L shaped table that is completely solid. So this table does not stand on legs, meaning that beneath the top of the table is not empty as it would be with a table with legs. The setup is that I am using a concave mesh collider for the table. I am passing in it a non-static sphere collider that is a trigger and that has a kinematic rigidbody on a parent gameobject. Though mind you, the passing in happens via modifying the transform via the script. And not via rigidbody.MovePosition.

    When the sphere collider collides with the L shaped table, it calls the callback OnTriggerEnter. However, when I move the sphere collider inside so that it does not touch any faces of the table, an event OnTriggerExit is called, which is what I would like not to happen.

    When setting the collider on the table to convex, it works fine and OnTriggerExit() does not get called.
    I also tried it with a simple cube. Using a box collider or a convex mesh collider, it works as I expect it to. However, even for a simple cube if I switch it to concave, OnTriggerExit gets called.

    I suppose it is just the way that concave mesh calculations work and I really have no way to change this behavior other than to create multiple convex colliders?

    Best
     
  2. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    Yes create convex collider. You could use box colliders to approximate the table.
     
  4. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Thanks! I hoped there was an easier solution. It just feels unintuitive that for a closed volume, the solver thinks it is outside of the bounds, though it is not.

    Is this a bug or is this how the PhysX's implementation of concave colliders work?
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    It's intended. Generally there is a problem with concave volumes.
    Performant ways of determining it are still to be developed as I know. Math is not there yet :(
    Generally people are misleaded since we do have concave or even non manifold colliders that are kind of working, like terrain collider or static colliders.
    Problem is that what you get is a collision with mesh and not with a volume. This is why when you pass this mesh or get inside it you will not be push out of it.
     
    Wattosan likes this.
  6. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Thank you for the clarification, @koirat !