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
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
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
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.