コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static bool SphereSphereIntersects(BurstSphereCollider a, BurstSphereCollider b)
        {
            var combinedRadius = a.Radius * a.Scale + b.Radius * b.Scale;
            var distance       = Vector3.Distance(a.Center + a.Offset, b.Center + b.Offset);

            return(distance <= combinedRadius);
        }
コード例 #4
0
        public static bool SphereSphereIntersects2(ref BurstSphereCollider a, BurstSphereCollider b)
        {
            var totalRadius = a.Radius + b.Radius;
            var len         = a.Center - b.Center;
            var sqrLen      = len.x * len.x + len.y * len.y + len.z * len.z;

            return(sqrLen <= totalRadius * totalRadius);
        }
コード例 #5
0
        public void Update(Collider collider)
        {
            if (collider is SphereCollider sphere)
            {
                Sphere = BurstColliderFactory.CreateSphere(sphere);
            }

            if (collider is BoxCollider box)
            {
                Box = BurstColliderFactory.CreateBox(box);
            }
        }
コード例 #6
0
 public static BurstBaseCollider ToBaseCollider(this BurstSphereCollider sphere, int id) => new BurstBaseCollider
 {
     Type   = BurstColliderType.Sphere,
     Sphere = sphere,
     Id     = id,
 };
コード例 #7
0
 public static BurstBaseCollider ToBaseCollider(this BurstSphereCollider sphere) => new BurstBaseCollider
 {
     Type   = BurstColliderType.Sphere,
     Sphere = sphere
 };
コード例 #8
0
 public static Vector3 ClosestPosition(this BurstSphereCollider sphere, Vector3 worldPosition)
 {
     return((worldPosition - sphere.Center + sphere.Offset) * sphere.Radius * sphere.Scale);
 }
コード例 #9
0
 public static bool Contains(this BurstSphereCollider sphere, Vector3 worldPosition)
 {
     return(math.distance(worldPosition, sphere.Center + sphere.Offset) <= sphere.Radius * sphere.Scale);
 }
コード例 #10
0
 public static List <BurstSphereCollider> Intersects(this BurstSphereCollider testCollider, NativeArray <BurstSphereCollider> colliders)
 {
     return(IntersectionJobs.SphereSphereIntersectionJob.Execute(testCollider, colliders));
 }