- Home /
How to get the friction (factor) of the surface that the player is sliding on
I have a player that slides on different surfaces of increasing friction. What script can I write to get the friction that the player is currently colliding/sliding on?
screenshot-2021-01-28-234335.png
(36.0 kB)
Comment
Best Answer
Answer by Llama_w_2Ls · Jan 29, 2021 at 10:56 AM
You can get the properties of the Physics material assigned to your collider. For example:
BoxCollider col = GetComponent<BoxCollider>();
float dynamicFriction = col.material.dynamicFriction;
float staticFriction = col.material.staticFriction;
This works with all colliders with a physics material. @pnguin2
You would need to also find the collider your player is sliding on. You can use OnCollisionEnter for this.
Your answer
Follow this Question
Related Questions
Friction between two rigidbodies 0 Answers
Calculating required force for pushing a body to a desired position at once 0 Answers
Shooting a cannonball. 6 Answers
Direction of rotation and ApplyForce 1 Answer
AddRelativeTorque not rotating 1 Answer