Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

PhysicMaterial Scripting

Discussion in 'Physics' started by CC_Fan, Dec 22, 2014.

  1. CC_Fan

    CC_Fan

    Joined:
    Aug 4, 2014
    Posts:
    3
    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
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
  3. CC_Fan

    CC_Fan

    Joined:
    Aug 4, 2014
    Posts:
    3
    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?
     
  4. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,355
    The collision information is available via OnCollisionEnter/OnCollisionStay callbacks:

    http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

    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?
     
  5. CC_Fan

    CC_Fan

    Joined:
    Aug 4, 2014
    Posts:
    3
    Thank you very much :) 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 ;)