- Home /
Changing physical material impossible?
Hey,
Trying to change the friction on a physical material 2D at runtime
capsule.sharedMaterial.friction = 0;
Does not work, if i inspect the physical material it will say 0 but it isn't actually 0, it's still acting like 1.
The only way to make it work is by disabling and re-enabling the collider
capsule.sharedMaterial.friction = 0;
capsule.enabled = false;
capsule.enabled = true;
This causes a ton of issues, from triggers triggering constantly or not functioning to my character being stuck in walls, there has to be a proper way to do this??
I see this has been a problem since 2013 and possibly even earlier, is nothing being done about this, what is going on?
I would say keep a reference to the material itself somewhere and change the value in the material, and not the one applied on the Collider itself (I take it capsule
is of type Collider), and then reapply that material on top.
Not sure i understand Scoutas but i've made a public Physical$$anonymous$$aterial2D variable and assigned my mat to it, then i do:
phys$$anonymous$$at2D.friction = 0;
capsule.shared$$anonymous$$aterial = phys$$anonymous$$at2D;
It doesn't make a difference, i've even tried to set the capsule's material to null then re-assigning phys$$anonymous$$at2D and no difference!
Another question then. Did some poking around, found someone saying that the collider can't be a trigger. Try creating a new cube, add just a collider to it and try updating the Physics$$anonymous$$aterial2D then. If it works, then your setup of the capsule/player has a mistake somewhere
Unfortunately my collider isn't a trigger, ive tried it in an empty project as well and the same happens, i'm surprised that this has never been solved, either i'm doing something wrong or nobody has ever changed their physical material 2D at runtime.
Ive tried assigning and changing the physical material on the Rigidbody2D ins$$anonymous$$d, same problem, the Collider has to be disabled then re-enabled.
Answer by FortisVenaliter · Feb 03, 2017 at 10:10 PM
I don't see a "friction" variable in the Script Reference. Sure you aren't using a deprecated variable?
Ah, my apologies. Was looking at 3D ins$$anonymous$$d of 2D.