public static void PrepareColliders(ref ComponentArray <HitCollisionHistory> collections, int tick, int mask, Entity forceExcluded, Entity forceIncluded, ray ray, float rayDist, float radius) { Profiler.BeginSample("HitCollisionHistory.PrepareColliders [SphereCast]"); for (var i = 0; i < collections.Length; i++) { var collection = collections[i]; if (!IsRelevant(collection, mask, forceExcluded, forceIncluded)) { collection.DisableHitCollision(); continue; } var stateIndex = collection.GetStateIndex(tick); Profiler.BeginSample("-capsule test"); var boundCenter = collection.boundsCenterBuffer[stateIndex]; var rayEnd = ray.origin + ray.direction * rayDist; var closestPointOnRay = coll.ClosestPointOnLineSegment(ray.origin, rayEnd, boundCenter); var dist = math.distance(closestPointOnRay, boundCenter); var boundsHit = dist < collection.settings.boundsRadius + radius; Profiler.EndSample(); if (boundsHit) { collection.EnableCollisionForIndex(stateIndex); } else { collection.DisableHitCollision(); } if (HitCollisionModule.ShowDebug.IntValue > 0) { DebugPrimitiveModule.ClearChannel(HitCollisionModule.PrimDebugChannel); DebugPrimitiveModule.CreateCapsulePrimitive(HitCollisionModule.PrimDebugChannel, ray.origin + ray.direction * radius, ray.origin + ray.direction * (rayDist - radius), radius, Color.yellow, 5); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, boundCenter, collection.settings.boundsRadius, boundsHit ? Color.yellow : Color.gray, 5); } } Profiler.EndSample(); }
public static void PrepareColliders(ref ComponentArray <HitCollisionHistory> collections, int tick, int mask, Entity forceExcluded, Entity forceIncluded, sphere sphere) { Profiler.BeginSample("HitCollisionHistory.PrepareColliders [Sphere]"); for (var i = 0; i < collections.Length; i++) { var collection = collections[i]; if (!IsRelevant(collection, mask, forceExcluded, forceIncluded)) { collection.DisableHitCollision(); continue; } var stateIndex = collection.GetStateIndex(tick); var boundsCenter = collection.boundsCenterBuffer[stateIndex]; var boundsRadius = collection.settings.boundsRadius; var dist = math.distance(sphere.center, boundsCenter); var boundsHit = dist < sphere.radius + boundsRadius; if (boundsHit) { collection.EnableCollisionForIndex(stateIndex); } else { collection.DisableHitCollision(); } if (HitCollisionModule.ShowDebug.IntValue > 0) { DebugPrimitiveModule.ClearChannel(HitCollisionModule.PrimDebugChannel); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, sphere.center, sphere.radius, Color.yellow, 5); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, boundsCenter, boundsRadius, boundsHit ? Color.yellow : Color.gray, 5); } } Profiler.EndSample(); }
public static void PrepareColliders(ref ComponentArray <HitCollisionHistory> collections, int tick, int mask, Entity forceExcluded, Entity forceIncluded, ray ray, float rayDist) { Profiler.BeginSample("HitCollisionHistory.PrepareColliders [Ray]"); // Rollback for (var i = 0; i < collections.Length; i++) { var collection = collections[i]; if (!IsRelevant(collection, mask, forceExcluded, forceIncluded)) { collection.DisableHitCollision(); continue; } var stateIndex = collection.GetStateIndex(tick); Profiler.BeginSample("-raycast"); var sphere = primlib.sphere(collection.boundsCenterBuffer[stateIndex], collection.settings.boundsRadius); var boundsHit = coll.RayCast(sphere, ray, rayDist); Profiler.EndSample(); if (boundsHit) { collection.EnableCollisionForIndex(stateIndex); } else { collection.DisableHitCollision(); } if (HitCollisionModule.ShowDebug.IntValue > 0) { DebugPrimitiveModule.ClearChannel(HitCollisionModule.PrimDebugChannel); DebugPrimitiveModule.CreateLinePrimitive(HitCollisionModule.PrimDebugChannel, ray.origin, ray.origin + ray.direction * rayDist, Color.yellow, 5); DebugPrimitiveModule.CreateSpherePrimitive(HitCollisionModule.PrimDebugChannel, sphere.center, sphere.radius, boundsHit ? Color.yellow : Color.gray, 5); } } Profiler.EndSample(); }