Beispiel #1
0
        public static List <SphereCollisionInfo> DetectCollisions(Vector3 segment0, Vector3 segment1, float radius, int mask, IList <Component> ignoreColliders, List <SphereCollisionInfo> resultBuffer, float checkOffset = 0f, bool multipleContactsPerCollider = true)
        {
            resultBuffer.Clear();
            colliderBufferCapsule.Clear();

            ExtPhysics.OverlapCapsule(segment0, segment1, radius + checkOffset, ignoreColliders, colliderBufferCapsule, mask);
            if (colliderBufferCapsule.Count == 0)
            {
                return(resultBuffer);
            }

            for (int i = 0; i < colliderBufferCapsule.Count; i++)
            {
                contactsBufferCapsule = ExtCollider.ClosestPointsOnSurface(colliderBufferCapsule[i], segment0, segment1, radius + checkOffset, contactsBufferCapsule, multipleContactsPerCollider);

                for (int j = 0; j < contactsBufferCapsule.Count; j++)
                {
                    //We calculate sphereDetectionOriginInCapsule for our depenetration method since we need to know where the spheres detection origin would be within the capsule.
                    Vector3 sphereDetectionOriginInCapsule = Vector3.zero;
                    if ((colliderBufferCapsule[i] is CapsuleCollider || colliderBufferCapsule[i] is SphereCollider) && !ExtVector3.IsParallel(segment1 - segment0, contactsBufferCapsule[j].normal))
                    {
                        sphereDetectionOriginInCapsule = Geometry.ClosestPointsOnSegmentToLine(segment0, segment1, contactsBufferCapsule[j].point, contactsBufferCapsule[j].normal).first;
                    }
                    else
                    {
                        sphereDetectionOriginInCapsule = Geometry.ClosestPointOnLineSegmentToPoint(contactsBufferCapsule[j].point, segment0, segment1);
                    }

                    //We store just the radius, not radius + checkOffset, so that our depenetration method has the correct radius to depenetrate with.
                    resultBuffer.Add(new SphereCollisionInfo(true, colliderBufferCapsule[i], sphereDetectionOriginInCapsule, radius, contactsBufferCapsule[j].point, contactsBufferCapsule[j].normal));
                }
            }

            return(resultBuffer);
        }
Beispiel #2
0
        public static List <SphereCollisionInfo> DetectCollisions(Vector3 origin, float radius, int mask, IList <Component> ignoreColliders, List <SphereCollisionInfo> resultBuffer, float checkOffset = 0f, bool multipleContactsPerCollider = true)
        {
            resultBuffer.Clear();
            colliderBufferSphere.Clear();

            ExtPhysics.OverlapSphere(origin, radius + checkOffset, ignoreColliders, colliderBufferSphere, mask);
            if (colliderBufferSphere.Count == 0)
            {
                return(resultBuffer);
            }

            for (int i = 0; i < colliderBufferSphere.Count; i++)
            {
                contactsBufferSphere = ExtCollider.ClosestPointsOnSurface(colliderBufferSphere[i], origin, radius + checkOffset, contactsBufferSphere, multipleContactsPerCollider);

                for (int j = 0; j < contactsBufferSphere.Count; j++)
                {
                    //We store just the radius, not radius + checkOffset, so that our depenetration method has the correct radius to depenetrate with.
                    resultBuffer.Add(new SphereCollisionInfo(true, colliderBufferSphere[i], origin, radius, contactsBufferSphere[j].point, contactsBufferSphere[j].normal));
                }
            }

            return(resultBuffer);
        }