Search Unity

Raycast returns no collision when hitting very close to an edge

Discussion in 'Physics' started by invicticide, Feb 26, 2015.

  1. invicticide

    invicticide

    Joined:
    Nov 15, 2009
    Posts:
    109
    I have a tessellated plane mesh which serves as the ground. It's very nearly flat, and very simple. I do a raycast from one meter up, aiming down, with infinite distance. This raycast hits the mesh as you would expect...

    ...unless it happens to hit very near an outer edge (but still within the bounds of the mesh), in which case it reports no collision result at all.

    It's probably close enough to break floating-point precision, which is my best guess as to the problem (although I don't fully understand the mechanism by which that would fail), but I wonder if anyone else has a different perspective?

    Where this sucks for me is that I'm stitching a bunch of these planes together, and when I do a downward raycast to find the ground altitude at a point, it returns no result for one frame when you cross the boundary between meshes, even though that boundary is seamless.

    I know I can "just use SphereCast" to work around this, but I'm actually very curious why Raycast would exhibit this behavior.