Search Unity

Bug Box collider falls through convex mesh collider

Discussion in 'Physics' started by davej256, Mar 30, 2023.

  1. davej256

    davej256

    Joined:
    Nov 11, 2022
    Posts:
    17
    Been googling around, couldn't find anything. Here we go.

    I recently imported a 3D map. GM Construct from Garry's Mod. There's a mini grassy hilly area that I put mesh colliders on, and made them all convex.

    For my project, I'm manually ticking the physics engine and using my own code to interpolate between fixed timesteps. Yes, I know rigidbodies have an interpolation option. I need custom code for something different.

    This only happens sometimes, but when I drop my custom-interpolated cube on to a specific part of the collider, more-so the left part, it penetrates halfway into the ground, shoots out, then lands on the convex mesh collider and starts shaking. This doesn't happen if I disable convex, or use a box collider.

    Changing the physics collision detection mode does nothing.

    Right before the physics tick, I manually reset the position/rotation/velocity/angVelocity from the last tick, so that it's in the right spot after lerping on the render frames in-between. This seems to be causing it. If I disable my custom interpolation, it doesn't glitch out. Yet it works fine on every other type of collider.



    This is how it looks with the convex collider. I can't use box-collider long term since there's little inclines on the grass.

    The meshes themselves are pretty weird. All of the meshes are rotated 90 degrees X on import, and then the prefab itself transforms the X rotation of each mesh -90 degrees to counter it. Perhaps this is screwing with it?

    On the docs, it states that :
    For a Mesh Collider to work properly, the Mesh must be read/write enabled in any of these circumstances:

    • The Mesh Collider’s Transform has negative scaling (for example, (–1, 1, 1)) and the Mesh is convex.
    • The Mesh Collider’s transform is skewed or sheared (for example, when a rotated transform has a scaled parent transform).
    I have enabled "read/write" on the import setting. Still glitches out.

    Here's the source if anyone wants to test:
    https://www.models-resource.com/pc_computer/garrysmod/model/52997/

    Edit: I think I found the issue. The grass are made up of planes so they're paper thin. I don't think the convex colliders like this, but the docs mention that
    "A convex mesh is required by the physics engine to have a non-zero volume. Flat meshes such as quads or planes that are marked as convex will be modified by the physics engine to have a thickness (and therefore a volume) to satisfy this requirement."

    So then, why isn't it modifying it to work?

    Edit 2: If I flip the grass plane so the invisible backface is showing, the box seems to collide fine and doesn't penetrate or shake on top.
     
    Last edited: Mar 30, 2023