Collider2D.Cast doesn't detect some parts of my composite collider 2D
Hi
I'm doing a cast with a 2D collider in some of my scripts. I recently fixed a detection issue by changing the Geometry Type setting of my Composite Collider 2D to Polygons.
Now, when I do a cast with my 2D Collider, I don’t detect some parts of the Composite Collider 2D! If I got deeper, I instead detect some other part.
Here are two examples where I cast a 2D box towards the bottom, just a little bit, and I draw the normal multiplied by 1000 (in each of them, the box is clearly going threw the ground):
I also did a test to see if the same issue happens when I use OverlapCollider with trigger colliders. This issue doesn't happen with them.
Here is the code I'm using to test all of that:
private void Awake()
{
ContactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer));
ContactFilter.useLayerMask = true;
ContactFilter.useTriggers = false;
}
private void FixedUpdate()
{
HitBuffer = new RaycastHit2D[16];
int count = Collider.Cast(Vector2.down, ContactFilter, HitBuffer, 0.02f + ShellRadius);
foreach (RaycastHit2D hit in HitBuffer)
{
if (hit.collider)
{
Debug.DrawLine(hit.point, hit.point + hit.normal * 100.0f, Color.red);
}
}
Collider2D[] triggerColliders = new Collider2D[4];
Debug.Log(Trigger.OverlapCollider(ContactFilter, triggerColliders));
}
Is this a bug from Unity? I tried tinkering with settings, but I can't find a way to fix this.