Hi there,
I have a very simple scene with just a box entity with a physics shape and a physics body set to kinematic.
I am trying to cast a ray through it and get the number of resulting hits. I expect to get two hits, one from “entering” the collider and one from “exiting” but only get one.
I am under the impression it should be working since this is a very basic setup. Am I missing something ?
Any help is much appreciated
var CollisionWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;
var worldPosition = new int3(100, 200, 100);
var rayDirection = new int3(0, -1, 0);
var rayEnd = worldPosition + 1000 * rayDirection;
RaycastInput input = new RaycastInput()
{
Start = worldPosition,
End = rayEnd,
Filter = new CollisionFilter
{
BelongsTo = 1u << 0,
CollidesWith = 1u << 1,
GroupIndex = 0,
},
};
var hits = new NativeList<Unity.Physics.RaycastHit>(Allocator.Temp);
CollisionWorld.CastRay(input, ref hits);
var hitCount = hits.Length;
Debug.Log($"{hitCount}");