Search Unity

2D Character gets stuck when jumping into a collider

Discussion in 'Scripting' started by SeeleyBooth, Apr 16, 2014.

  1. SeeleyBooth

    SeeleyBooth

    Joined:
    Jan 23, 2014
    Posts:
    30
    So I am working on a 2 side scroller. I have a 4 legged character the runs left and right and jumps.

    I have short walls that the character jumps over. Works good.

    Problem comes in when moving forward, if i jump to late to make it over the wall the character bumps into the wall but stays stuck where it hits the wall collider.

    If i stop moving forward the character will fall to the floor like it should but I cant figure out how to stop sticking to the wall if i jump into it while moving forward.

    Any help would be awesome!
    Thanks.
     
  2. SeeleyBooth

    SeeleyBooth

    Joined:
    Jan 23, 2014
    Posts:
    30
    Just in case anyone else finds this. I found the solution. Create a 2d physics material apply it to the collider then turn down the friction
     
  3. Eiznek

    Eiznek

    Joined:
    Jun 9, 2011
    Posts:
    374
    This only happens if you allow movement control while in the air. There are much nicer ways to handle this in code. If your using a basic movement controller your probably using OnCollisionStay and that's just always setting your character to grounded. If you do a raycast down at the feet to make sure the feet or at least one foot is hitting then set Grounded to true or false. This will solve that issue was well.
     
  4. SeeleyBooth

    SeeleyBooth

    Joined:
    Jan 23, 2014
    Posts:
    30
    I will definatly give that a try. Thank you.
     
  5. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    @Eiznek your solution sounds awesome, can you provide a sample?