Esempio n. 1
0
        /// <summary>
        /// Checks if this collider and the given collider collided.
        /// Returns CollisionDetails about any detected collision.
        /// Returns null if no collision was detected.
        /// </summary>
        //public abstract CollisionDetails CheckCollision (CheckCollisionSettings settings, Collider other);
        public CollisionDetails CheckCollision(CheckCollisionSettings settings, Collider other)
        {
            if (other == null)
            {
                return(null);
            }

            Collider_Circle thisCircle = this as Collider_Circle;
            Collider_Sphere thisSphere = this as Collider_Sphere;

            Collider_Circle otherCircle = other as Collider_Circle;
            Collider_Sphere otherSphere = other as Collider_Sphere;

            //TODO: Hairy hairy hairy
            if (thisCircle != null)
            {
                if (otherCircle != null)
                {
                    return(CheckCollisionMethods.CheckCollision(settings, thisCircle, otherCircle));
                }
                else if (otherSphere != null)
                {
                    return(CheckCollisionMethods.CheckCollision(settings, thisCircle, otherSphere));
                }
            }
            else if (thisSphere != null)
            {
                if (otherCircle != null)
                {
                    return(CheckCollisionMethods.CheckCollision(settings, thisSphere, otherCircle));
                }
                else if (otherSphere != null)
                {
                    return(CheckCollisionMethods.CheckCollision(settings, thisSphere, otherSphere));
                }
            }

            return(null);
        }
Esempio n. 2
0
 public static CollisionDetails CheckCollision(CheckCollisionSettings settings, Collider_Circle colOne, Collider_Sphere colTwo)
 {
     return(CheckCollision(settings, colTwo, colOne));
 }
Esempio n. 3
0
        public static CollisionDetails CheckCollision(CheckCollisionSettings settings, Collider_Circle colOne, Collider_Circle colTwo)
        {
            Vector3 colOnePos = colOne.GetPosition();
            Vector3 colTwoPos = colTwo.GetPosition();

            //	Zero one of the axis based on the upAxis for 2D collision
            colOnePos = new Vector3(
                (settings.upAxis == VectorAxis.X) ? 0 : colOnePos.x,
                (settings.upAxis == VectorAxis.Y) ? 0 : colOnePos.y,
                (settings.upAxis == VectorAxis.Z) ? 0 : colOnePos.z);

            //	Zero one of the axis based on the upAxis for 2D collision
            colTwoPos = new Vector3(
                (settings.upAxis == VectorAxis.X) ? 0 : colTwoPos.x,
                (settings.upAxis == VectorAxis.Y) ? 0 : colTwoPos.y,
                (settings.upAxis == VectorAxis.Z) ? 0 : colTwoPos.z);

            float sqrDistance  = colOnePos.SqrDistanceTo(colTwoPos);
            float colOneRadius = colOne.ScaledRadius;
            float colTwoRadius = colTwo.ScaledRadius;

            float totalSqrRadius = (colOneRadius + colTwoRadius) * (colOneRadius + colTwoRadius);

            if (sqrDistance > totalSqrRadius)
            {
                return(null);
            }

            CollisionDetails details = new CollisionDetails(colOne, colTwo);

            return(details);
        }