Search Unity

Different Friction for Different Sides of a Quad...

Discussion in '2D' started by datahead8888, Nov 5, 2015.

  1. datahead8888

    datahead8888

    Joined:
    Nov 5, 2015
    Posts:
    55
    I am writing a 2D platformer. My walking / running is implemented by adding a horizontal velocity to the player. I found the player would stick to walls if he pushed against them while falling. I solved this by setting the friction for those objects to 0 using a Physicsl2D material. However, for quads that function as both walls and ground tiles, this means you will slide out of control on top of them. What is the standard way to have different friction on the side of an object and the top of an object?

    I realize I could use additional intersection tests to detect if the top, bottom, right side, or left side of the player is intersecting with the quad and adjust the friction of the quad at runtime. This just seems like a hack, though.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    I believe what you are looking for are Platform Effector 2D. These can not only be used to make two-way platform, they can also add side friction and side bounce.
     
  3. ianmcelvain

    ianmcelvain

    Joined:
    Jan 28, 2014
    Posts:
    37
    Yeah my platformer, as of right now is using a physics 2d material called wall with .00001 friction and assigned to all walls.
    I half assed it because i have bigger mechanics to fix.

    I also see if you already assigned and Input.GetButtonDown("Vertical") to your character, while its next to a wall, if tap the input(jump) fast it just jumps along the wall.

    Now im either going to write a rule for when these colliders (characters / wall) touch to not stick or just find a better way
     
  4. datahead8888

    datahead8888

    Joined:
    Nov 5, 2015
    Posts:
    55
    I managed to fix this bug for now by disabling walking / running when the script detects that the player is adjacent to a wall, but I will keep this suggestion in mind in the future. Thanks for the tip.

    My character does seem to be able to stick to the corner of ground tiles still. This could be related to my usage of a circle collider for him, however.