IsSphereWithinCollider.cs 583 B

12345678910111213141516171819
  1. using UnityEngine;
  2. namespace Rokid.UXR.Interaction
  3. {
  4. public static partial class Collisions
  5. {
  6. public static bool IsSphereWithinCollider(Vector3 point, float radius, Collider collider)
  7. {
  8. Vector3 boundsPoint = collider.bounds.ClosestPoint(point);
  9. if (Vector3.SqrMagnitude(boundsPoint - point) > radius * radius)
  10. {
  11. return false;
  12. }
  13. Vector3 closestPoint = collider.ClosestPoint(point);
  14. return Vector3.SqrMagnitude(closestPoint - point) <= radius * radius;
  15. }
  16. }
  17. }