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); }
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 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); }
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); }
public void Update(Collider collider) { if (collider is SphereCollider sphere) { Sphere = BurstColliderFactory.CreateSphere(sphere); } if (collider is BoxCollider box) { Box = BurstColliderFactory.CreateBox(box); } }
public static BurstBaseCollider ToBaseCollider(this BurstSphereCollider sphere, int id) => new BurstBaseCollider { Type = BurstColliderType.Sphere, Sphere = sphere, Id = id, };
public static BurstBaseCollider ToBaseCollider(this BurstSphereCollider sphere) => new BurstBaseCollider { Type = BurstColliderType.Sphere, Sphere = sphere };
public static Vector3 ClosestPosition(this BurstSphereCollider sphere, Vector3 worldPosition) { return((worldPosition - sphere.Center + sphere.Offset) * sphere.Radius * sphere.Scale); }
public static bool Contains(this BurstSphereCollider sphere, Vector3 worldPosition) { return(math.distance(worldPosition, sphere.Center + sphere.Offset) <= sphere.Radius * sphere.Scale); }
public static List <BurstSphereCollider> Intersects(this BurstSphereCollider testCollider, NativeArray <BurstSphereCollider> colliders) { return(IntersectionJobs.SphereSphereIntersectionJob.Execute(testCollider, colliders)); }