Physics.SphereCastNonAlloc is returning incorrect information.
int count = Physics.SphereCastNonAlloc(transform.position, radius, moveVector.normalized, collisions, 1, layerMask);
The hit info that this populates the collision list with is returning incorrect normals and points.
It’s returning the inverse of my moveVector as the normal and [0, 0, 0] as the point.
I’ve been struggling with this for hours and can’t seem to find an answer to my problem.
You are doing something wrong. Layermask is not the final argument in EITHER of the Method’s contructors.
Physics.SphereCastNonAlloc doesn’t have this note in the documentation, but the documentation for Physics.SphereCastAll has the following note:
Notes: For colliders that overlap the sphere at the start of the sweep, RaycastHit.normal is set opposite to the direction of the sweep, RaycastHit.distance is set to zero, and the zero vector gets returned in RaycastHit.point. You might want to check whether this is the case in your particular query and perform additional queries to refine the result. Passing a zero radius results in undefined output and doesn’t always behave the same as Physics.Raycast.
We were only interested in the point and it didn’t have to be that precise. So we checked for every returned hit if the distance was 0f, and used hit.collider.bounds.center instead of hit.point.