Example #1
0
        public override bool RayCast(BubbleRay ray, out float distance)
        {
            distance = float.MaxValue;
            bool    result = false;
            Vector2 vp     = ray.Orign - m_start;

            if (Vector2.Dot(vp, m_normal) <= 0)
            {
                return(false);
            }

            Vector2 v1 = m_start + m_normal * ray.Radius;
            Vector2 v2 = m_end + m_normal * ray.Radius;

            float tempDistance;

            if (ray.IntersectionSegment(v1, v2, out tempDistance))
            {
                if (tempDistance < distance)
                {
                    distance = tempDistance;
                    result   = true;
                }
            }

            return(result);
        }
        public override bool RayCast(BubbleRay ray, out float distance)
        {
            distance = float.MaxValue;
            bool    result        = false;
            Vector2 orignToCenter = m_center - ray.Orign;
            float   proj          = Vector2.Dot(orignToCenter, ray.Direction);

            if (proj >= 0)
            {
                Vector2 p         = ray.Ray.GetPoint(proj);
                Vector2 cp        = m_center - p;
                float   cpdis     = cp.magnitude;
                float   sumRadius = m_radius + ray.Radius;
                if (cpdis == sumRadius)
                {
                    distance = proj;
                    result   = true;
                }
                else if (cpdis < sumRadius)
                {
                    float delta = Mathf.Sqrt(sumRadius * sumRadius - cp.sqrMagnitude);
                    distance = proj - delta;
                    result   = true;
                }
            }

            return(result);
        }
Example #3
0
        public override bool RayCast(BubbleRay ray, out float distance)
        {
            distance = float.MaxValue;
            bool result = false;

            if (m_verticles.Count != 6)
            {
                return(false);
            }

            for (int i = 0; i < m_verticles.Count; i++)
            {
                Vector2 start, end;
                start = m_verticles[i];
                if (i == m_verticles.Count - 1)
                {
                    end = m_verticles[0];
                }
                else
                {
                    end = m_verticles[i + 1];
                }

                float tempDistance;
                LineBubbleCollider lc = new LineBubbleCollider(start, end);
                if (lc.RayCast(ray, out tempDistance))
                {
                    if (tempDistance < distance)
                    {
                        distance = tempDistance;
                        result   = true;
                    }
                }
            }

            return(result);
        }
Example #4
0
 public virtual bool RayCast(BubbleRay ray, out float distance)
 {
     distance = float.MaxValue;
     return(false);
 }