I’ve recently been tinkering around with the Rigidbody component for a main character, although I seem to be running into a problem where should you jump against the wall, the object just kind of sticks there. Worse still, if you hit jump at the same time, it shoots the Rigidbody into the air.
I found a couple of potential fixes using raycasts, although I wanted to make sure that there isn’t just an simpler approach for detecting when you’re colliding with a vertical surface as opposed to a horizontal one.
There is new unity component called platform Effector 2D that will allow you to do that:
more info here:
I had a similar problem. Here’s what has been proposed:
Your simple solution is to apply a new physics object to walls that has no friction. This has a few disadvantages, though, which make it an unattractive (albeit simple) solution.
That link has a raycast solution which should help. Beware spline ramps and stairs with this, though.
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. (image included for reference)
No need for any extra coding, raycasts, etc. Enjoy!
With this method, he still stuck to walls for me. I fixed it by changing the Friction & Bounce Combine settings from “Average” to “Multiply” with the Dynamic & Static Friction set to 0.
How about attaching a trigger to the thing you’re jumping against and have a function that when inside that trigger makes your character unable to jump.
change your rigidbody2d components interpolate variable to exterpolate
i had this issue once, i’m unable to exactly copy-past ecode, because it was a long time ago, maybe you too are writing your own character controller and also apply the gravity manually (yourself)?
if i remember correctly, my problem was that i kept my downward force code in the ELSE condition, i later removed it from Else and wrote it outside the IF ELSE condition which gathers the input and dpes the movement.
this meant that a constant force was applied regardless of what Input the game was getting. it was just a minor logical mistake really…
if you haven’t already, you should raycast downwards and check if the Player is grounded or not also.
I found out that using “Platform Effector 2D” also helps.
The help states:
“The Platform Effector 2D applies various platform behavior such as one-way collisions, removal of side-friction/bounce and more.”