public static bool BoxSphereIntersects(BurstBoxCollider box, BurstSphereCollider b, out IntersectionInfo info) { info = new IntersectionInfo(); var closest = box.ClosestPosition(b.Center); var distToClosest = Vector3.Distance(b.Center, closest); var gapDistance = distToClosest - b.Radius; var centerToClosest = closest - b.Center; var overlapVector = (b.Radius - distToClosest) * centerToClosest.normalized; info.GapDistance = gapDistance; info.IsIntersecting = gapDistance <= 0 ? 1 : 0; info.PointOnB = closest + overlapVector; info.PointOnA = closest; if (gapDistance <= 0) { info.PenetrationDirection = overlapVector; info.PenetrationDistance = overlapVector.magnitude; return(true); } info.GapDirection = overlapVector; return(false); }
public static bool BoxSphereIntersects(BurstBoxCollider box, BurstSphereCollider sphere) { var closestPosition = box.ClosestPosition(sphere.Center + sphere.Offset); var distance = Vector3.Distance(sphere.Center + sphere.Offset, closestPosition); return(distance - sphere.Radius * sphere.Scale <= 0); }