public static CollisionDetails CheckCollision(CheckCollisionSettings settings, Collider_Sphere colOne, Collider_Sphere colTwo) { Vector3 colOnePos = colOne.GetPosition(); Vector3 colTwoPos = colTwo.GetPosition(); 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); }
public static CollisionDetails CheckCollision(CheckCollisionSettings settings, Collider_Sphere colOne, Collider_Circle colTwo) { Vector3 colOnePos = colOne.GetPosition(); Vector3 colTwoPos = colTwo.GetPosition(); // If it is supposed to be flattened, // zero one of the axis based on the upAxis for 2D collision if (colTwo.flattenAxisIn3D) { 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); }