PhysicsCollider.Value.Value.CastRay()

Hello, don’t know if this is a bug, but using PhysicsCollider.Value.Value.CastRay() reports a hit even when the ray is totally contained inside the collider. Is that intended?

Its kinda by design so until there’s another way to ignore itself(which afaik is planned) you need to use a custom collector. there’s an example in the official repo

To cut to the chase though here’s what I’ve been using for my own shooting raycasts(note theres code that isnt used, just havent gotten around to tidying this up)

    public struct IgnoreSpecificEntityCollector: ICollector<RaycastHit>
    {
        public Entity IgnoreEntity;

        public bool EarlyOutOnFirstHit => false;
        public float MaxFraction { get; private set; }
        public int NumHits { get; private set; }

        private RaycastHit m_ClosestHit;
        public RaycastHit Hit => m_ClosestHit;

        public IgnoreSpecificEntityCollector(Entity ignoreEntity,float maxFraction)
        {
            IgnoreEntity = ignoreEntity;
            //m_World = world;
            m_ClosestHit = default(RaycastHit);
            MaxFraction = maxFraction;
            NumHits = 0;
        }

        #region ICollector

        public bool AddHit(RaycastHit hit)
        {
            if (hit.Entity.Equals(IgnoreEntity))
                return false;
       
            MaxFraction = hit.Fraction;
            m_ClosestHit = hit;
            NumHits = 1;
      
            return true;
        }

        #endregion
    }

to use it

var collector = new IgnoreSpecificEntityCollector(entity, 1.0f);
var hit = CollisionWorld.CastRay(rayInput, ref collector);