Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Physics for ECS' started by Mr-Mechanical, Nov 14, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    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).
     
  2. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    70
    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.
     
    steveeHavok and Mr-Mechanical like this.
  3. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    Small note, ConvexConvexDistanceQueries.ConvexConvex() implements GJK/EPA, which you'll find by digging into BodyBody() as Rory suggested.
     
  4. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507