Why is my spherecast returning an incorrect hit on mesh collider? (Unity)

by IanLarson   Last Updated September 14, 2018 01:13 AM

enter image description here

I have a mesh collider that is largely a flat plane facing up. Any SphereCast against that surface should return a normal of Vector3(0, 1, 0), but that isn't always happening. When near an edge on the mesh, the cast will penetrate the face and register the hit against the edge as if it was a corner when it's really just a polygon edge on a flat surface This is giving me inaccurate hit points and normals.

Hopefully the image above is interpretable. The light blue circle is where the SphereCast should stop and the pink circle is where it seems to be stopping. Instead of hitting the face (horizontal black line) and returning the proper normal (green line), it's ignoring the face and hitting the tri's edge (diagonal black line) and returning a lerped normal (red line) as if it were a corner.

Is the SphereCast that inaccurate against mesh colliders, or am I doing something wrong? Is there anything I can do to fix this?

Related Questions

Why are my smooth curved meshes bumpy?

Updated July 19, 2015 13:05 PM

Finding the closest point on a concave mesh (Unity C#)

Updated February 24, 2018 00:13 AM