- Home /
How do you change Friction on a collider material?
I'm trying to make a universal function for changing the friction on any object whether it has a sphere collider, box collider, mesh collider, or capsule collider.
This is not working for a box resting on a tilted plane.
function changeFriction(go:GameObject,amount:float);
//var go=GameObject.Find("box1");
go.GetComponent(Collider).material.staticFriction=amount;
go.GetComponent(Collider).material.dynamicFriction=amount;
go.GetComponent(Collider).material.frictionCombine=PhysicMaterialCombine.Minimum;
}
I would expect changeFriction(0) to make the box have zero friction and slide off the plane, but it doesn't change the friction.
It only seems to work if I set the plane to have zero friction also and use BoxCollider instead of Collider.
Is there a way to make a universal friction changer for any type of collider and without adjusting the plane friction each time?
$$anonymous$$ake function with component parameter ins$$anonymous$$d of GameObject parameter
private void ChangeFriction([NotNull] Component col, float amount)
{
col.GetComponent<Physic$$anonymous$$aterial>().dynamicFriction = amount;
col.GetComponent<Physic$$anonymous$$aterial>().staticFriction = amount;
}
Answer by abdullahsyyd · Apr 03, 2017 at 06:45 AM
@dansav You can try by using PhysicsMaterial, it can help you to make and adjust differnet friction values of your colliders.
Your answer
![](https://koobas.hobune.stream/wayback/20220612114543im_/https://answers.unity.com/themes/thub/images/avi.jpg)