Raycast2D passing through EdgeCollider2D

Hi,

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?

This’ll be a bug in Box2Ds b2ChainShape::RayCast which EdgeCollider2D uses. Specifically it calls into b2EdgeShape::RayCast.

Can you please submit a bug report with a super simple reproduction case?

Thanks, I’ve filed a bug report.

Awesome. Can you send me the case number when you have it so I don’t have to wait for QA to process it?

When should I expect to receive a case number? I haven’t had any sort of confirmation email yet.

You normally get them fairly quickly. Can you give me the title you used for the case? I can try to search the system for it.

Failing that, either submit it again and/or host the repro project for me to download.

I believe the title was something like ‘Raycast passes through EdgeCollider2D’.

Perhaps I mistyped my email.

Anyway I’ve uploaded the project here:
http://www.badviking.com/misc/EdgeColliderBugRepro.zip

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.

Great, thanks so much for all your help, I really appreciate it.