Platformer, character gets stuck on walls

Hello,

I’m making a platformer using 2D Toolkit. Right now I’m using the Unity 2D sample character as placeholder, and I noticed that whenever I jump up against a wall or floating platform, the character gets stuck on it.

Now I’ve googled this a bit, and I read several replies about raycasting, but I have no idea what that is or how that works, as I’m kinda new to scripting.

So I guess my question is does anyone know how to fix this problem, and an explanation of how I can incorporate that fix?

The idea behind raycasting is that there is a ray being cast out from the player in the direction(s) the player is moving. This ray ends up colliding with walls or other platforms long before the player does. This allows your script to know, each frame, how far the player can move before movement must be stopped. Each frame, as long as the player continues moving, that distance becomes shorter and shorter until eventually it reaches the edge of the wall. At that point, movement is stopped before the character’s sprite ends up going inside the wall.
The whole purpose of doing it this way is so that the player never ends up inside the wall. With some collision detection, once the player’s bounding box (or BoxCollider2D in Unity) collides with a wall’s bounding box, the player is then pushed out of the wall. This is a messier solution that doesn’t look as good.
The raycasting method allows for preemptive collision detection. Your code will know when collision will occur before it happens, rather than when it is already too late.

So you’re saying I should use raycasting or not?

I’d definitely recommend using raycasting. I use it in my games and the collision is always flawless.

I just added a Physics2D material with zero friction to the colliders on my character, it’s slippery on the edges, but it does work. Does this method cause any problems, considering it’s such a quick fix?

I just use circle colliders on Characters…it helps…but if you jump and go forward it will stick…had the same problem with staying on a platform/…I just added the right amount of friction to keep the Character on it