Friction Wont Update Correctly

if(Input.GetKey(KeyCode.W)){
collider.material.staticFriction=0;
collider.material.dynamicFriction=0;

}
else
{
//collider.material.staticFriction=100;
collider.material.dynamicFriction=100;
}

In this code I want the player body to stick to the ground with heavy friction when the W button is not pressed. and to glide when the W key is pressed. The problem is it wont update at every frame instead it only responds if the collider encounters a new collider like if the player hits a wall or jumps and comes back down on the ground. How can I get it to change the friction as soon as I press or release the move button.

Thanks,
Austin

Perhaps try function FixedUpdate(). Because of physics related codes, you will need to call fixed update instead of update to update correctly. Though i have no idea what you are trying to achieve.

nope that didn’t work. If you are confused, I need to change the friction on the moment the button is pressed, however it only decides to change, if the object collides with something that it is not currently touching. I’m wondering if the problem is caused by unity only calling for the friction at the start of a collision, rather than continuously calling for it.