[Solved] Reusing the ECS convex collision intersection code for non-physics related ECS tasks

Hello,

I would like to reuse some code for my ECS project. I could either recreate a GJK/EPA algorithm or reuse a comparable implementation already implemented in Unity ECS Physics. Does anyone have any experience reusing this functionally in their own projects that they would be willing to share? I am looking for a full-on convex-convex collision detection that goes beyond the API (Collider Casts/Raycasts/Distance Queries).

Hi, the key function to start looking at is Unity.Physics.ManifoldQueries.BodyBody() - this produces collision manifolds between a pair of colliders. You can dig down from there to the convex-convex collision detector and other types of pairs.

Those functions are marked internal right now but you can change them to be public locally to experiment. Our hope is that they are designed to be flexible enough to be usable in different contexts, so it would be great to hear how you get on with them.

2 Likes

Small note, ConvexConvexDistanceQueries.ConvexConvex() implements GJK/EPA, which you’ll find by digging into BodyBody() as Rory suggested.

3 Likes

Thank you for these responses, they are very helpful towards my project, I am now looking into resuing the entire Broadphase system for convex hulls as well, for the optimal performance.