I have run into a problem where on some rare occasions my raycasts are passing through edge colliders. In the following example there is a single edge collider made up of multiple points and the ray is passing through precisely at a vertex.
The first image is what should happen and what does happen a good portion of the time (ray is projected down from above and it hits the first edge it comes to):
Then simply by changing the y coordinate of my ray origin this happens:
Or sometimes even this (note that the bottom edge of my shape also has a vertex precisely where the ray passes through):
Oh and I should probably mention that a polygon collider is not suitable for my scenario but more importantly I think this is probably a unity bug.
Has anyone else ever run into this? I couldn’t find any other mentions of it anywhere. Any suggestions on a solution?
It’s easy enough to reproduce, just run the project in the editor and select the RayDropper object in the hierarchy so that you can manually adjust its y position. You should find that the ray snaps to the origin for certain y values indicating that it has passed through the edge collider.
I’ve not looked at the case but I just found it with title “Raycast passes through EdgeCollider2D at vertices” case 895732. It was closed two days ago by QA with an email reply to your email address:
Not sure if that makes sense to you or not.
EDIT: I just had a quick look at the case and I can duplicate your issue so I’ll get it reopened and assign it to me for investigation. Thanks for the bug report; with the volume of bug reports it seems that sometimes, good ones get deflected, sorry about that.