How Exactly Does Friction Work?

I have exactly 2 2d box colliders. one being floor and the other one being player with rigidbody2d with a mass of 1 and linear drag of 0. Now I have floor collider with physics matterial2d of 0.4 friction. If I set physics material of player to 0 friction, floor friciton does not apply. But if I set it to 0.1, I get close results on my formula.

Vector2 predictVelocity(Rigidbody2D rigidbody, Vector2 forceThatWillBeApplied, float friction)
    {
//friction = 0.4f
        Vector2 frictionForceNormalized = -forceThatWillBeApplied.normalized * friction * Physics2D.gravity.magnitude * rigidbody.mass * 0.5f; //0.5f because 2 contact points as stated in the documentations
        Vector2 nextVel = rigidbody.velocity + (forceThatWillBeApplied + frictionForceNormalized) * Time.fixedDeltaTime / rigidbody.mass;
        return nextVel;
    }

But here is the thing, I don’t seem to get the player’s friction scale’s place in this formula. Why does setting it to 0.1 gives very close results while setting it to anything other than 0.1 gives different results? Does player’s transform scale got any effect here? How does player’s friction comes into play when floor already have friction?

You can find the code for friction and restitution (bounce) here: https://github.com/erincatto/Box2D/blob/master/Box2D/Dynamics/Contacts/b2Contact.h as “b2MixFriction” and “b2MixRestitution” respectively.

2 Likes

Thank you. So when I send this as parameter to the function

Mathf.Sqrt(playerFriction * floorFriction)

and remove 0.5f multiplier from the formula, it works as expected. Thank you again.