/// <summary> /// Measures the distance between 2 spheres. If the value is negative, the spheres are overlapping. /// </summary> /// <param name="s1"></param> /// <param name="s2"></param> /// <returns></returns> public static float DistanceBetween(Sphere s1, Sphere s2) { return (s1.Center - s2.Center).magnitude - (s1.Radius + s2.Radius); }
public static Sphere GetGlobalBoundingSphere(this GameObject go, BoundingSphereAlgorithm algorithm, bool bRecurseChildren = true) { var s = new Sphere(go.transform.position, 0.0f); if (go.renderer != null) s.Encapsulate(go.renderer.GetGlobalBoundingSphere(algorithm)); if (go.collider != null) s.Encapsulate(go.collider.GetGlobalBoundingSphere(algorithm)); if (bRecurseChildren) { foreach (Transform child in go.transform) { s.Encapsulate(GetGlobalBoundingSphere(child.gameObject, algorithm, bRecurseChildren)); } } return s; }
/// <summary> /// Measures the distance between 2 spheres. If the value is negative, the spheres are overlapping. /// </summary> /// <param name="s1"></param> /// <param name="s2"></param> /// <returns></returns> public static float DistanceBetween(Sphere s1, Sphere s2) { return((s1.Center - s2.Center).magnitude - (s1.Radius + s2.Radius)); }