unity-game-enginerigid-bodiesphysics-engine

How to prevent sliding with rigid bodies in Unity?


So, I am using Unity's Rigid body physics engine. And I made the player using a capsule collider. And after creating another rigid body with a Box collider I tried to jump onto it, only, the player starts to ever so slightly slide on top of it until eventually sliding off.

I want to be able to make the player jump onto movable objects without sliding on top unless there is enough of a slope to make sense for the player to slide off of. Is this possible, or does Unity's physics engine prevent this?


Solution

  • This can be achieved by applying a Physic Material to the player's capsule collider. Specifically, take a look at the Dynamic Friction and the Static Friction of the Physic Material. You may also want to set the Friction Combine to Maximum, if you want to ensure your player has a good grip on the platform regardless of what kind they land on.

    A higher Dynamic Friction will quickly stop your player object if it starts sliding, while a higher Static Friction will make it harder for the player object to start sliding if it is otherwise stationary.

    There isn't an exact science behind choosing these values; you'll really have to play around with it to see what feels right for your game.