PhysicMaterial Scripting

Hi,

In my current Project I have a ball in a winter environment. So there is snow on the ground (high friction) and on the surfaces with a higher angle I have ice (low friction). As this is only one mesh, I cannot apply different PhysicMaterials to it. For rendering I use a shader which uses the normals to calculate which texture to draw and I would like to do the same for the physics material (friction). Is there an easy way to do this?

Thanks CC_fan

You could do raycasts against the ground and then modify either player/ball’s physics material properties or the ground that the raycast is hitting.

See Unity - Scripting API: PhysicMaterial.frictionDirection2 for an example of changing the physics material parameters at runtime…

Raycasting against the ground won’t work in my project, as the ground is not always “down”. Specificly I have a Ball in a tube with (as said) snow on the bottom and ice on the walls and the ceiling. So I do have to find an other way to detect witch part I am colliding with. Is there a way to directly get the collision information from the physics engine?

The collision information is available via OnCollisionEnter/OnCollisionStay callbacks:

The ContactPoint structure includes the world point of the collision, which you can wind backwards into a similar value lookup for your object (i.e. matching it up with UV coordinates on a texture for painted friction values, or whatever matches up with your current workflow)…

At some point, though, it might just be easiest to use multiple colliders in your level for each area that needs different friction values?

Thank you very much :slight_smile: As I am using a sphere as character the normal of the surface of the collision point is calculated quite easy from the collision point and therefor the friction can be calculated quite easy as well :wink: