I just want to use it like how you pass LayerMask to Physics.Raycast, but I can’t seem to get it working.
Here is my ray code:
public static RaycastInput GetRayInput(float3 start, float3 end, LayerMask collisionMask)
{
return new RaycastInput
{
Start = start,
End = end,
Filter = new CollisionFilter
{
BelongsTo = ~0u,
CollidesWith = (uint)collisionMask.value,
GroupIndex = 0
}
};
}
public static bool IsVisibleThroughGeometry(CollisionWorld collisionWorld, float3 pointA, float3 pointB, LayerMask obstacleMask)
{
var input = GetRayInput(pointA, pointB, obstacleMask);
collisionWorld.CastRay(input, out var closestHit);
LogEntityName(closestHit.Entity);
// If does not hit an obstacle, then it is visible
return closestHit.Entity == Entity.Null;
}
[BurstDiscard]
static void LogEntityName(Entity entity)
{
Debug.Log(World.DefaultGameObjectInjectionWorld.EntityManager.GetName(entity));
}
Logging the Entity name shows that hit entity does not belong to the layer I have provided as LayerMask. What am I missing here?