Making a rigidbody (character) land on a slope without moving/sliding

So I’m trying to make a decent rigidbody character controller in unity, and I’m stuck with this problem:

As you may notice from this gif, when I jump and land on a slope, my character seems to slide down the slope a little. I’m trying to find a way to make the character not move at all when it lands.

I’ve unsuccessfully tried the following, which basically resets the velocity to zero when the character detects a collision while it was in the air:

void OnCollisionEnter(Collision coll)
    {
        if (CurrentControllerState == ControllerState.InAir)
        {
            _characterRigidbody.velocity = Vector3.zero;
        }
    }

I’ve Debug.Log()'d a bit and this code really DOES execute at the right time, but the character still moves a bit. Friction doesn’t change anything either. I’m guessing this is due to the fact that the collision resolves its position in the direction of the slope’s normal when the character’s collider intersects the slope’s collider, making the character move a little. But that’s just a guess. Here’s another gif to show you exactly what’s happening, frame by frame:

Also, this character’s rigidbody does not use gravity. Instead, I manually apply artificial gravity whenever it is not touching any ground.

Does anyone have ideas on how I could fix this?

I’m still having the same problem. Did you manage to come up with a fix?

The fix was not to use rigidbody physics and instead use a kinematic rigidbody, that does OverlapCapsules and ComputePenetration to solve its collisions manually

However, I could pretty easily think of another solution to this problem (with rigidbody physics) now. At every fixed update, capsuleCast your velocity and look for collisions. If you find a collision, modify your velocity so that it’ll arrive flush with the ground (and with a little offset for safety) on the next fixedupdate

1 Like