Search Unity

[SOLVED] 2D physics material friction not behaving as shown in inspector

Discussion in 'Physics' started by TLOZ, Jan 8, 2015.

  1. TLOZ

    TLOZ

    Joined:
    Jul 20, 2014
    Posts:
    10
    I've tried to describe the issue in this image:

    halp.png

    I can't think of any additional information that I could/ should post, but of course I'll provide more if needed.




    ...also, a brief text-only description of the issue in case you can't access the image:

    Essentially I'm changing the friction of a 2D physics material assigned to all 2D colliders of my character based on a boolean variable called 'grounded'. 'grounded' is true if a 2D overlap circle (at the feet/ base of the character) detects any other colliders (excluding the character colliders, they're on a different layer). It works fine (I use it for animations and the jumping mechanics), so I don't think it's related to the issue.

    Anyway, the important piece of code is


    // Set friction
    if ( grounded == true ) {
    cat_physics_material.friction = 0.6;
    }
    else if ( grounded == false ) {
    cat_physics_material.friction = 0f;
    }


    'cat_physics_material' being the 2D physics material.

    The change of frictions shows up fine in the inspector, but the actual, in-game friction is different. So, even though the friction displays as 0 in the air (grounded == false), the friction seems to be 0.6 (character gets stuck in wall and doesn't fall to the ground, grounded remains false since the overlap circle doesn't collide with walls). On the other hand, when landing on the ground, while frictions shows up as 0.6, the character slides on the ground completely frictionless.

    If I comment the snippet of code out and set friction to either 0 or 0.6, everything works as expected (it's just that I need the friction to change).

    I somewhat expect me just missing an option to enable or something, but yeah; I can't really figure this one out myself so help's certainly appreciated!
     
  2. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    i don't have an answer for you, only a suggestion. have you considered swapping between two physics materials instead? that may yield better results
     
  3. TLOZ

    TLOZ

    Joined:
    Jul 20, 2014
    Posts:
    10
    Thanks for the reply! Someone over at reddit actually pointed me to this unity forum thread. The solution described there (turning off/on colliders on physics material change) seems to work fine from what I can tell.
     
    Nanako likes this.