Physical object stacks in the 'floor'

Topics: Developer Forum, User Forum
Jul 15, 2013 at 4:04 PM
I will give you a link to describe my problem:

So, the code, which create all the bodies:
Vertices verts = PolygonTools.CreateRectangle(rect.Y / 2, rect.X / 2,
    new Vector2(rect.Y / 2, rect.X / 2), 0);

PolygonShape shape = new PolygonShape(verts, den);

entity.Body = BodyFactory.CreateBody(machine.RealWorld);

Fixture fix = entity.Body.CreateFixture(shape);
Did somebody faced that problem?
Jul 15, 2013 at 5:37 PM
Edited Jul 15, 2013 at 5:37 PM
It is probably the most common "problem" with farseer/box2d. Short answer: Your approach will never work reliably. For a detailed breakdown of the problem and suggested solutions take a look at:

I'd recommend that blog for a lot of "beginner" problems with farseer in general.

Regarding tile-based engines: It is never a good idea to naively construct your solid collision geometry directly from your tiles. You'll run into all kinds of problems and probably generate a lot more fixtures than you need, which is not good for the performance either.

I'd highly recommend to use edge shapes (or chain shapes) with ghost vertices. It is not to hard to parse your tiles and combine all colinear tile edges to one edge shape.

...or even better: Just use an existing editor like Tiled:
It has build in support for object layers, where you can place arbitrary polygons, which you can use for collisions and convert to a chain shape directly.
Jul 15, 2013 at 11:30 PM
Thanks for your help!

I have read the acticles.

So, after a playing with my code i got even more question =\

I am create all my objects like this:

And when player and bricks both made from the Edges - collisions doesn't happen at all.
And the second question: Is it requireable to make a moving body from top and bottom shapes?
Jul 16, 2013 at 3:41 AM
Edges (edgeshape) do not collide with other edges, as they are infinitely thin, and therefore do not have a definable collision logic. Only use edges for terrain - use polygons for characters and other game objects.
Jul 16, 2013 at 12:01 PM
Ok, thanks!

But i still don't get why ghost verts doesn't solve the problem, since i implemented them into terrain.
I will come back with visual interpretation later :P
Jul 16, 2013 at 11:31 PM
I still got this problem =\

Here are ghost vertices:


the code:
            float offsetX1 = -0.2f;
            float offsetX2 = 0.2f;
            float offsetY1 = -0.05f;
            float offsetY2 = -0.05f;

            eTop.HasVertex0 = true; eTop.HasVertex3 = true;
            eTop.Vertex0 = new Vector2(eTop.Vertex1.X + offsetX1, eTop.Vertex1.Y + offsetY1);
            eTop.Vertex3 = new Vector2(eTop.Vertex2.X + offsetX2, eTop.Vertex1.Y + offsetY2);