Unity physics bug, falling through terrain

I have a terrain collider with my terrain and my player (3d model with own controller, rigid body, box collider…) can walk on terrain but some random times, when it collides with a wall or another gameObject, it starts falling through terrain as if it was “quicksand” then it falls with gravity. I guess it is because the collision may try to push the player down on Y axis and due to some instant lag or something, it goes through terrain then it no longer detects collision.

Is there any way to solve this?

I'm using rigid body velocity, not translating position

1 Answer

1

I would suggest to use a “Capsule Collider”. Also, setting the “Collision Detection” of your Rigidbody to “Continuous Dynamic” should help minimize missing collisions.

If you are not using the controller provided with the Unity Standard Assets, I could imagine, that you maybe are directly accessing the transform.position to move the character. If so, this would be the cause of your problem. It is important to not directly change the characters Transform component, but instead use the Rigidbody to move the character. Here is the official tutorial about Character movement: https://unity3d.com/learn/tutorials/projects/stealth-tutorial-4x-only/player-movement

This is a basic but VERY useful tip (not accessing the player's transform position directly). I have not personally tried to use the Capsule Collider however I will give it a try!

I'm using rigid body velocity not translations by the way, why would you use capsule collider instead?