Platformer Collison Detection - Player getting stuck on edges

Topics: Developer Forum
Jul 5, 2012 at 10:04 PM

Here is my problem: http://dl.dropbox.com/u/29728961/problem.png. The player gets stuck on edges, vertically and horizontally! I've read similar threads, like this one: http://farseerphysics.codeplex.com/discussions/239360/, but couldnt solve this problem. I even read box2d documentation, they seem to have solved this problem using "ghost vertices", but farseer is built upon an earlier version of box 2d.

Can anyone point me in any direction to avoid this problem?

Thanks in advance!

Jul 5, 2012 at 11:06 PM

Farseer is based on the latest released Box2D which is 2.2. So they are pretty much up to date. Also ghost vertices apply to chain shapes whereas you seem to be having problems with polygon to polygon collisions. There is out-of-the-box solution for those. Check this for explanation:

http://www.iforce2d.net/b2dtut/ghost-vertices

Also make your character collision shape have round edges and it should help a lot.

Jul 6, 2012 at 12:47 AM

It's because in the home page it says farseer was based on Box 2d 2.1.2, and this "ghost vertices" feature was introduced in box 2.2, as you said.

I tried making the character edges round but I may be doing that wrong. Gonna try it again. Thanks a lot! Hope I can get it right this time.

Aug 9, 2012 at 6:55 AM

Still couldnt solve the issue. Is there any way to really make use of ghost vertices in farseer? Any tips on how to avoid this problem?
I'm already making as many tiles in one colision line as possible, but even so, sometimes the player still gets stuck on the edges or special tiles. What can I do?

Thanks in advance!

Aug 9, 2012 at 10:53 PM

You can use the LoopShape which automatically sets the ghost vertices based on adjacency or use multiple EdgeShapes and manually set HasVertex0=true,HasVertex3=true and  then Vertex0 and Vertex3 based on some heuristic you make up (like making the line Vertex1,Vertex2 a bit longer and setting Vertex0 and Vertex3 to the new ends or making a spline passing through v1 and v2 etc.).

Aug 10, 2012 at 8:19 AM

Thank you very much! That did solve my problem.

If anyone is found in the same situation, use something like this:

FarseerPhysics.Collision.Shapes.EdgeShape edgeShape = new FarseerPhysics.Collision.Shapes.EdgeShape(start, end);

//Defining the Ghost Vertices (if needed)
edgeShape.HasVertex0 = true;edgeShape.HasVertex3 = true; edgeShape.Vertex0 = new Vector2(edgeShape.Vertex1.X - 0.2f, edgeShape.Vertex1.Y-0.2f); edgeShape.Vertex3 = new Vector2(edgeShape.Vertex2.X + 0.05f, edgeShape.Vertex1.Y + 0.2f);

That's it! Thanks again!