Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Beating dead horse (rigidbodies sticking to walls)

Discussion in 'Physics' started by darkhog, Jun 22, 2015.

Thread Status:
Not open for further replies.
  1. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    I know I am probably beating dead horse here, but couldn't google out it. My character has 100% physics-based movement, done with a rigid body. Said rigidbody never rotates (aside of Y axis) due constraints. Unfortunately, when I jump towards a wall, rigid body sticks until I release forward button. Tried to make physic materials, but unfortunately it doesn't work.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    stop adding force when its off the ground.
     
  3. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    But then it won't maneuverable in the air. This is a colorful 3D platformer, with things like double jumps and mid-air U-turns, not hyperrealistic military shooter with brown and gritty graphics.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    The only solution you have is to not apply force in the direction of the wall... how you do that is your choice.
     
  5. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Ah, fudge it. Since it doesn't affect movement too much, I'll just include this as "feature" in character's moveset. Also works quite nicely when moving on the wall, so...
     
  6. dylanjosh

    dylanjosh

    Joined:
    Jun 1, 2015
    Posts:
    10
    Good idea. if only we could do that with everything :p
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,346
    This is a normal issue - out of the box, things that hit a wall in the air won't slide down it if it's getting force applied in the direction of the wall. The easiest fix is to do a raycast in the direction of your input, and null out the horizontal velocity if you're adjacent to a wall in that direction.

    You should also put your player character on continous dynamic collision detection, as that'll prevent it from clipping slightly into walls and the ground on the frame the character hits those things.
     
  8. GreenSignalGames

    GreenSignalGames

    Joined:
    Jul 11, 2017
    Posts:
    6
    For anyone else running into this issue, as I have a thousand times, I finally found a virtually perfect solution. On the character with the Rigidbody, you will also have a collider (usually a capsule collider). Copy that component, make the copy slightly wider, and slightly shorter, than the original. Match the height of the original, and then put the frictionless material on this collider. Now, the "feet" of your character will have the friction of the original capsule (you won't slide down slopes) but the "walls" of the new capsule will be what collides with other wall objects, and you will slide down them correctly.

    No need for any extra coding, raycasts, etc. Enjoy!
     
  9. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    608
    Oh wow.... I could hug you now. After 4 years of bumbling work arounds.. this was the simplest and "most elegant"... thanks man
     
    the_real_ijed likes this.
  10. pjbaron

    pjbaron

    Joined:
    Jan 12, 2017
    Posts:
    53
    @GreenSimpleGames thank you! Brilliant, simple, effective solution!
    I made my extra capsule just a tiny bit shorter (height) so there's a circular contact area rather than a single contact point for the friction collision. I found this helps when going up ramps with a Y 'locked' character (otherwise the touch point was zero friction being slightly forward of the very bottom).
     
  11. HyperBeeCore

    HyperBeeCore

    Joined:
    Oct 13, 2013
    Posts:
    11
    What do you mean by "Match the height of the original?" I'm having trouble getting this to work and I think I'm misunderstanding
     
    Mashimaro7 likes this.
  12. pjbaron

    pjbaron

    Joined:
    Jan 12, 2017
    Posts:
    53
    When you duplicate the capsule collider, you adjust the height of the duplicate to be a little shorter than the original one, but at the same Y offset, also make the radius a bit larger.

    What you're doing is putting a frictionless 'shell' around the outside of the original capsule except at the very bottom and top.
    The original capsule gives your feet some friction so you don't slide on ice all the time but it also sticks to walls. The new capsule will slide down walls, so having the original sticking out a little bit at the bottom means you get both:
    - feet with friction
    - body not sticking to walls!
     
    yojancuchau and KyleTeller like this.
  13. HyperBeeCore

    HyperBeeCore

    Joined:
    Oct 13, 2013
    Posts:
    11
    AH, I understand now. Thank you! Can't wait to give this a shot.
     
  14. Slauthering

    Slauthering

    Joined:
    May 29, 2020
    Posts:
    1
    Thanks for this beautiful and easy to apply solution.
    I like to add that you should apply the "Minimum" "Friction Combine"-option.
    Without it i still had the sticking to the wall problem.

    Physics_Mat.jpg
     
  15. Forvex8

    Forvex8

    Joined:
    Jun 19, 2022
    Posts:
    1
    Thank you. <3 You saved my hours.
     
  16. Jaumebv

    Jaumebv

    Joined:
    May 6, 2022
    Posts:
    1
    saved, ty ♥
     
  17. ryusdarling

    ryusdarling

    Joined:
    Oct 20, 2022
    Posts:
    2
    i love you, this solution saved me. i hope everyone who has this problem sees this answer :)
     
Thread Status:
Not open for further replies.