Hey guys. We use a SphereCast to ground our player. It misses some of our mesh colliders and teleports the player down to the floor below.
Here is a example
We SphereCast from the center of the sphere in the picture and with the same radius as the sphere. The istant the sphere cast is completly over the green line and do no longer hit the pavement it will miss the building mesh collider and teleport player down to the floor below.
My theory is that this counts as we are inside the mesh collider and raycasts ignore colliders they are inside. Can I somehow fix so the raycasts does not ignore the mesh collider?
Physics.SphereCast:
“Notes: SphereCast will not detect colliders for which the sphere overlaps the collider.”
I think you’re right in that the next collider is considered to be “inside” your sphere before the cast is performed.
You might be able to work around this by using a simple Raycast instead of a SphereCast. Or ensure the SphereCast is performed from above the ground instead of “on” it.
Thanks fro reply, A raycast is not god enough, the player must be able to walk on smaller gaps etc without falling down on the floor beneath. Could do both offcourse, at the cost of performance. Or add a boxcolider to all mesh colliders that you can walk on Hmm, I dont know. Which would you guys do?
Plystire’s suggestion about starting the SphereCast higher, maybe even inside the character, will solve your problem. There’s no need to mix raycasts with sphere casts, nor add boxcolliders to all meshes that you can walk on.
Higer up is not the problem, the problem is that the SphereCast is fired from within the mesh. We solved it with a extraraycast if we detect the distance being greater from spherecast point to ground than in last frame. So it will only trigger the extra raycast if it misses the spherecast or if you are going down hill.