1
\$\begingroup\$

I am currently working on a 2D platformer in Unity. I am using a prefab from the AssetStore for my character (The last paragraph contains a link to the prefab). The character has a circle collider for his feet so that he can walk up slopes.

The problem I'm having is that because it is a circle collider, he also slides down any slope. I realize that I can add a Physics Material to the collider with a friction variable to stop (or at least resist) the sliding, but if I add any friction above ~0.1 the character can collide with a wall to stop himself from falling and yet 0.1 isn't even enough to stop him from sliding down slopes.

So my question is, how can I stop the character from sliding down slopes in a way that doesn't allow the player to stop himself from falling by colliding with walls?

The prefab that I'm using specifically is an asset found here, it's disk location is Sample Assets/2D/Prefabs/2D Character

\$\endgroup\$
  • \$\begingroup\$ There is more to it. What values do you have for drag and mass? Having a higher drag might help. You pushing the character or are you actually rolling the circle collider? \$\endgroup\$ – aggsol Sep 10 '14 at 14:04
  • \$\begingroup\$ Your issue may not be with the material attached, but with the way in which you move your character... Altering your characters rigidbody velocity directly will cause this issue with a frictioned material... Try using the rigidbody.addforce method to move your GameObject instead... \$\endgroup\$ – Savlon Oct 4 '14 at 16:04
1
\$\begingroup\$

Sticking to walls is a problem mentioned in this Unity learning module around 8:45, and they set the friction of the ground to zero to solve it. However, they don't address the sliding down slopes problem.

Option 1: Give the character's body a frictionless rectangle collider that is just wider than the circle collider at it's feet, with its bottom positioned half way up the circle collider. The rectangle will hit the wall instead of the feet, and the character will slide right down. You could do 2 angled plane colliders instead of a rectangle, one on either side of the player, as a rectangle collider's bottom corners could get caught on the ground when falling off cliffs - angled planes wouldn't if positioned well.

Option 2: play with physics values. You can spend a lot of time playing with those values. Increasing the linear drag on the player's rigidbody would help, as that dampens its movement. But you'll also have to repeatedly tweak your gravity, mass, and the force applied to the character when the player moves it until you find a good balance.

Option 3: use a collider for the walls that has a friction of zero, and walking surfaces get a collider with a positive friction. This is obviously more resource intensive, but that might not be a problem for you.

\$\endgroup\$
0
\$\begingroup\$

I believe your character is more rolling than sliding, since it have circle collider.

You may try to set large angular damping for character's body when it receive no control forces.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.