SphereCast and CheckSphere failing to catch collisions.

Basically I need to know what inner workings can make these checks false, even though everything I can see indicates they should be true. Details below:

Trying to make a gameobject warp to a point, but it must check for a valid destination first.

Step 1:
If a SphereCast hits something, use the hit point for step 2 (warps to closest edge of thick objects)
If not, use the spherecast termination point for step 2 (limits distance that can be covered by a warp)

Step 2:
Do a CheckSphere at the coordinates from step 1 for added insurance.
If it hits nothing, this should be a valid location to warp to.

And that’s all wonderful when it works, but it frequently fails in this scenario:
Both checks always fail together (seemingly). I’ll often wind up stuck inside thick objects if the desired warp point was close to the thick object’s center. The failures seem to only occur when the warping object is in direct contact with the obstacle object. I can see that causing the SphereCast to fail, but it seems like a CheckSphere should realize it’s completely inside of a BoxCollider, right?

None of the objects can move during the check. The checks are performed in one frame in FixedUpdate, and I’ve toyed with improving the physics solver quality and fixed timestep.

Any advice as to why this can fail?

First something that might give you a little insight.

Physics.SphereCast will return false if the imaginary sphere starts its “sweep” while already inside of an object.

Basically, you can think of Physics.SphereCast as:

if(!Physics.CheckSphere(transform.position,...)) //if the current position is not occupied
    Physics.SphereCast(); //then cast the sphere as you would suspect

Looking at why they would both fail, knowing this, I would guess that what is happening, is that from Physics.SphereCast() the default RaycastHit information is being returned: normal = Vector3(0,0,0), distance = 0, etc. This would mean the next check is checking at the origin of your map Vector3(0,0,0) in world space and looking for a collision within whatever radius. Try removing any colliders from the position Vector3(0,0,0) in world space and see if the second statement returns true every single time. If so then that was why the second statement was failing. The fix for the first statement is relatively hard, I would suggest using a smaller radius for the spherecast (by at least 0.11).

Furthermore: in edit (tab)–>project settings–>physics you can change the variable “min penetration for penalty” to a lower number like 0.01 or 0.005 (or lower although it is the law of diminishing returns) until the collisions are precise enough for your tastes, which should make everything work better. (If you do this, instead of subtracting 0.11 from the radius you can subtract 2*n + 0.01 instead.)