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
- Objects with Universal Render Pipeline/Particles/Lit shader are always lit up when changing their Rendering Layer Mask
- PolySpatial “Trying to set shader on a Material Variant.” error is printed in the console when entering Play Mode
- Error “Shader error in 'YSCloudCover': call to 'tex3D' is ambiguous at Assets/YSCloudCoverText.shader(606) (on d3d11)“ is present when compiling tex3D shader with DXC
- Placeholder asset is not loaded with Advertisement Legacy sample when using the latest version of the package
- Addressables content build fails but the Player build is successful when building a development build
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.