public unsafe void RigidBodyCastColliderTest() { Physics.RigidBody rigidbody = Unity.Physics.RigidBody.Zero; const float size = 1.0f; const float convexRadius = 0.0f; const float sphereRadius = 1.0f; var rayStartOK = new float3(-10, -10, -10); var rayEndOK = new float3(10, 10, 10); var rayStartFail = new float3(-10, 10, -10); var rayEndFail = new float3(10, 10, 10); rigidbody.Collider = (Collider *)BoxCollider.Create(new BoxGeometry { Center = float3.zero, Orientation = quaternion.identity, Size = size, BevelRadius = convexRadius }).GetUnsafePtr(); var colliderCastInput = new ColliderCastInput(); var closestHit = new ColliderCastHit(); var allHits = new NativeList <ColliderCastHit>(Allocator.Temp); // OK case : Sphere hits the box collider colliderCastInput.Start = rayStartOK; colliderCastInput.End = rayEndOK; colliderCastInput.Collider = (Collider *)SphereCollider.Create( new SphereGeometry { Center = float3.zero, Radius = sphereRadius } ).GetUnsafePtr(); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput)); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput, out closestHit)); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput, ref allHits)); // Fail case : wrong direction colliderCastInput.Start = rayStartFail; colliderCastInput.End = rayEndFail; Assert.IsFalse(rigidbody.CastCollider(colliderCastInput)); Assert.IsFalse(rigidbody.CastCollider(colliderCastInput, out closestHit)); Assert.IsFalse(rigidbody.CastCollider(colliderCastInput, ref allHits)); }
public unsafe void RigidBodyCastColliderTest() { Physics.RigidBody rigidbody = Unity.Physics.RigidBody.Zero; const float size = 1.0f; const float convexRadius = 0.0f; const float sphereRadius = 1.0f; var rayStartOK = new float3(-10, -10, -10); var rayEndOK = new float3(10, 10, 10); var rayStartFail = new float3(-10, 10, -10); var rayEndFail = new float3(10, 10, 10); rigidbody.Collider = (Collider *)BoxCollider.Create(float3.zero, quaternion.identity, new float3(size), convexRadius).GetUnsafePtr(); var colliderCastInput = new ColliderCastInput(); var closestHit = new ColliderCastHit(); var allHits = new NativeList <ColliderCastHit>(Allocator.Temp); // OK case : Sphere hits the box collider float3 rayDir = rayEndOK - rayStartOK; colliderCastInput.Position = rayStartOK; colliderCastInput.Direction = rayDir; colliderCastInput.Collider = (Collider *)SphereCollider.Create(float3.zero, sphereRadius).GetUnsafePtr(); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput)); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput, out closestHit)); Assert.IsTrue(rigidbody.CastCollider(colliderCastInput, ref allHits)); // Fail case : wrong direction rayDir = rayEndFail - rayStartFail; colliderCastInput.Position = rayStartFail; colliderCastInput.Direction = rayDir; Assert.IsFalse(rigidbody.CastCollider(colliderCastInput)); Assert.IsFalse(rigidbody.CastCollider(colliderCastInput, out closestHit)); Assert.IsFalse(rigidbody.CastCollider(colliderCastInput, ref allHits)); }