I am facing an issue where capsule cast is not detecting a mesh collider. This happens in very narrow scenarios and by my estimate this is only occurring around intersection points between mesh colliders.
The capsule cast passes through the mesh collider around its intersection point with another mesh collider. The intersection then occurs at the subsequent edge detected.
The capsule cast returns an invalid intersection point, calculating a gravity pass after this step causes the controller to fall through the surface.
I have conducted various tests for this controller and it works perfectly in any other scenario apart for this.
I examined in detail any part of the code that could be responsible for this, but after quite some testing I can assure that the problem is arising due to collision not being detected by Capsule Cast. I expect the capsule cast to provide accurate collision information.
I examined the mesh import properties and mesh collider settings, I also fiddled with Physics settings but the problem still persists.
This is part of the code responsible for the Capsule Cast.
Vector3 GetCapsuleCylindricalLength()
{
return Vector3.up * (halfHeight - radius + skinWidth);
}
Vector3 CapsuleStart(Vector3 position) { return position + GetCapsuleCylindricalLength(); }
Vector3 CapsuleEnd(Vector3 position) { return position - GetCapsuleCylindricalLength(); }
float samplingRadius = radius - skinWidth;
float distance = velocity.magnitude + skinWidth;
Physics.CapsuleCast(capsuleStart, capsuleEnd, samplingRadius, velocity.normalized, out RaycastHit hit, distance, collisionMask)