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

RaycastHit Barycentric Coordinate

Discussion in 'Physics for ECS' started by CerebralDaemon, Oct 25, 2021.

  1. CerebralDaemon

    CerebralDaemon

    Joined:
    Feb 15, 2020
    Posts:
    1
    In the non-ECS physics API, there is a barycentric coordinate inside RaycastHit, which provides a way to acquire the exact normal at the point of contact with a collider: https://docs.unity3d.com/ScriptReference/RaycastHit-barycentricCoordinate.html

    Is there an equivalent way to achieve this using DOTS Physics? The RaycastHit returns a ColliderKey, which can be used in the PhysicsCollider to acquire the Collider and, using GetChild / GetLeaf, a ChildCollider, which has a RigidTransform, and this seems to have a position and a rotation; unfortunately I don't know enough about how the colliders and collisions are handled under-the-hood to know for sure if this is what I need, hence my question here.

    First of all, am I correct to think that the rotation inside the RigidTransform is the normal at that position of the Entity's Collider, and that I could use it alongside the hit's contact point similarly to the example code in the doc provided above? However, even if that's the case, I still only have one normal; how can I get my hands on what I need to make my calculations? I've seen that the Collider has a GetLeaves function that takes a collector; would that be the correct approach? What's the difference between a collider's childs and leaves?