- Home /
How to change friction after collision?
I am trying to get traditional 2D platforming controls in my game, and one of the issues is getting the player to slide along walls and ceilings but stick to floors.
I would like to avoid assigning materials to every collider in the game, so what I am attempting to do is change the physics material on the player on the fly.
In the OnCollision functions I do this:
collider.material.dynamicFriction = 0;
collider.material.staticFriction = 0
...
// If the normal is mostly pointing up, don't slide on this surface.
if(contact.normal.y > 0.9f)
{
collider.material.dynamicFriction = 1;
collider.material.staticFriction = 1;
}
This appears to be assigning the friction values as I expected, but the problem seems to be that if friction is changed after the collision occurs, the changes to friction do not affect it. It basically takes the friction values at the time of collision, and never looks at them again.
Is there a way to force it to recheck those value? Or a virtual function that gets called prior to collision?
Thanks!