- Home /
SphereCast hitting edge of collider, returning "random" normal directions
The green line represents the centre of the spherecast, the radius of the spherecast is currently 0.2. The pink line is the hit normal, coming out from the hit point. As you can see, the hit point on the edge of the collider and the direction returned is not perpendicular to any of the sides of the box collider. The only time it returns a "correct" direction is when the whole of the spherecast intersects with one of the faces. The closer the center of the cast (green) is to the edge, the more the direction (pink) faces the floor.
Now I do get it, I get why it would be hitting the edge, but come on, that's terrible, The point of a surface normal is to return the normal of the surface, aka the polygon.
This is a huge problem and if this is an intended feature of physx then shame on them. Anyone had this problem hold them back? Any solutions? I need to spherecast, I cannot use a raycast.
The hit.normal is kind of the opposite direction of where the collision came from. Since you're spherecasting into or near an edge it seem's it's getting interpolated because of the volumetric nature of a sphere and a cube. It's about choice what one would define as "THE" contact point or surface normal when there's volumes and not points.
The only way I could do this was to get one contactpoint, or the center in between all of them and raycast against that point on the hit collider the get the surface normal for that particular point.
So solution: Raycast only for surface normals. (Or comparing adjacent mesh normals with localized collision point yourself ;) )