# Is there a ComputePenetration equivalent?

Discussion in 'Physics for ECS' started by hippocoder, Nov 11, 2019.

### Digital ApeModerator

Joined:
Apr 11, 2010
Posts:
29,723
Prepping to port to UP and want volumetric data that this function so conveniently provides with physx.

2. ### Rory_Havok

Joined:
Jun 25, 2018
Posts:
70
ICollidable.CalculateDistance() returns negative distance in the case of penetration, with an appropriate separation normal. You can call that on a collider, body or world. I think that should be equivalent?

hippocoder and PhilSA like this.
3. ### PhilSA

Joined:
Jul 11, 2013
Posts:
1,926
out of curiosity, do ColliderCasts do the same if the shape of the cast is already intersecting something else at its Start pose? Does it return the real normal of the "most penetrating point" as well as the accurate negative fraction with which we could calculate the penetration distance? And what does it do with the hit.Position in that case?

Last edited: Nov 11, 2019
4. ### MaxAbernethy

Joined:
Mar 16, 2019
Posts:
53
Hi PhilSA, ColliderCasts with an initial intersection will return a fraction of zero and the same position and normal as if you had done CalculateDistance at the ray start position. The penetration distance is not reported, which is unfortunate because the penetration distance can be very expensive to calculate, and if you call CalculateDistance it would have to be calculated a second time.

Here is a way to quickly calculate the penetration distance given the information returned from the query. The normal gives you the separating direction, and the position gives you the support point on the hit shape in that direction, so you only need to find the support point on the query shape in the opposite direction. GetSupportingVertex() in ConvexConvexDistance.cs shows how to do that, you just search for the vertex that has the highest dot product with the negative of the normal. Subtract the support point on the hit shape from the support point on the query shape, dot with the hit normal, and subtract the query shape's ConvexRadius to get the distance. It should be a negative number if the shapes are intersecting.