Search Issue Tracker

By Design

Votes

0

Found in

2018.4

2019.4

2019.4.18f1

2020.2

2021.1

2021.2

Issue ID

1309208

Regression

No

Physics.ComputePenetration returns incorrect values when Box or Mesh Colliders interacts with non-convex Mesh Collider

Physics

-

How to reproduce it:
1. Open the user's attached project 'ComputePenetrationProblem.zip'
2. Load the 'SampleScene'
3. Select and drag the 'BoxCollider' GameObject along the X-axis over the plane In the Scene view
4. Observe the red box and the red line in the Scene view

Expected result: The red box moves along with 'CubeVisual' above the plane, and the red line is perpendicular to a plane
Actual result: The red box changes position and the red line changes direction when 'BoxCollider' approaches the mesh's edges

Reproducible with: 2018.4.31f1, 2019.4.19f1, 2020.2.3f1, 2021.1.0b4, 2021.2.0a3

Notes:
- Reproducible when GameObject has a convex Mesh Collider
- Not reproducible when GameObject uses Sphere, Capsule, or Mesh Colliders
- Not reproducible when the plane has a convex Mesh Collider

  1. Resolution Note:

    Actually, the minimum penetration direction for mesh is computed for a set of mesh triangles that are overlapped by the box initially. In this particular case, there is just one large triangle that is considered, and when the box is close to its edges, it will be shorter distance to move in the triangle plane over the edges compared to the distance it takes to pull the whole long box along the normal. This is the intended behaviour of this function.

    PhysX has another utility function that Unity doesn't expose, here: https://github.com/NVIDIAGameWorks/PhysX/blob/ae80dede0546d652040ae6260a810e53e20a06fa/physx/include/extensions/PxTriangleMeshExt.h#L138

    That function works by calling the regular ComputePenetration iteratively until it finds a satisfying result. The implementation is fairly simple, check it here: https://github.com/NVIDIAGameWorks/PhysX/blob/ae80dede0546d652040ae6260a810e53e20a06fa/physx/source/physxextensions/src/ExtTriangleMeshExt.cpp#L127

    An alternative approach would be to minimise the penetration depth in the first place. In case the wild overlap is a result of some character movement, it's advised to subdivide the movement into smaller steps. Hope that helps.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.