- Home /
2D character controller getting stuck on walls
I followed this tutorial: 2D Character Controllers to make a character for a 2D platformer. But I noticed one problem: if I'm pressing the directional key towards a wall while the character is in the air, they will stick to the wall and stop falling. The character controller knows that it's not grounded, so I don't know what the problem is. How do I work around this?
Are you sure it knows it's not grounded (logging?) It's possible the bottom is clipping in to the wall.
Answer by satyagames · Oct 01, 2014 at 05:37 PM
Apply a "slippery" physics material to the character's box collider.
i.e, Assets > Create > PhysicsMaterial2D and simply changed the friction variable to 0 from the inspector and apply to walls as well as character.
I think I understand why the walls need to be slippery (but not floors), but why does the character also have to be slippery?
UPDATE: Seems I only need to update the character collider box to no friction, not the walls. Opposite of what I thought.
Physical materials can be setup in a way that allows the character to take the $$anonymous$$imum friction values of the objects that it is in contact with, so when in contact with the wall it will react with very low friction, but when in contact with the floor it will not react with low friction(as if they both have a high friction then the $$anonymous$$imum(smallest) value of the two is still big). Hope you can understand my explanation :)
Answer by SparrowHawk666 · Mar 13, 2016 at 03:32 PM
add box colider then click 'Used by Effector' add a component 'platform effector2d' untick 'one way' and if you are using Gronded with ground layer then and the items to this layer...
This worked well for me.
I'd like to add that my specific problem was my character getting hung up on corners (as it was technically touching the top collider that had friction on it) and trying to compensate by giving the wall physics material more corner space meant sliding off the platforms in a frustrating way.
The way I finally fixed this while using SparrowHawk's method was to increase the "Side Arc" value on the Platform Effector to around 75 and my character was treating the corners more correctly.
Answer by SparrowHawk666 · Mar 13, 2016 at 03:32 PM
i.e, Assets > Create > PhysicsMaterial2D and simply changed the friction variable to 0 from the inspector and apply to walls ONLY,
Answer by orrinjones · May 23, 2017 at 06:35 AM
This as been a while but I will still add my input for anyone else who might be having the same issue. While the above method might work. You may alternative adjust the skin width of the character controller. Hope that helps
Answer by StudioZooka · Jan 27 at 11:13 PM
https://www.youtube.com/watch?v=eJik78bWSg0
This tutorial fixed the issue for me
Your answer
Follow this Question
Related Questions
Moving platform player bounce when moving down 1 Answer
How to make character stop at wall? 1 Answer
Character clips into the ground in 2D platformer 0 Answers
Rigidbody2D velocity changes when moving through a platform collider. 1 Answer
How to make character move up walls and along the ceiling? 0 Answers