Strange behavior of vertices

Jul 24, 2011 at 1:34 AM

Hi, I have a problen when creating bodies from vertices. I used this code to create the polygon (stairs)

Vertices verticesstairs01 = new Vertices(20);
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(0), ConvertUnits.ToSimUnits(256)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(0), ConvertUnits.ToSimUnits(216)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(40), ConvertUnits.ToSimUnits(216)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(40), ConvertUnits.ToSimUnits(176)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(80), ConvertUnits.ToSimUnits(176)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(80), ConvertUnits.ToSimUnits(136)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(120), ConvertUnits.ToSimUnits(136)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(120), ConvertUnits.ToSimUnits(96)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(163), ConvertUnits.ToSimUnits(96)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(160), ConvertUnits.ToSimUnits(56)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(352), ConvertUnits.ToSimUnits(56)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(352), ConvertUnits.ToSimUnits(96)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(392), ConvertUnits.ToSimUnits(96)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(392), ConvertUnits.ToSimUnits(136)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(432), ConvertUnits.ToSimUnits(136)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(432), ConvertUnits.ToSimUnits(176)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(472), ConvertUnits.ToSimUnits(176)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(472), ConvertUnits.ToSimUnits(216)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(512), ConvertUnits.ToSimUnits(216)));
            verticesstairs01.Add(new Vector2(ConvertUnits.ToSimUnits(512), ConvertUnits.ToSimUnits(256)));

            PolygonShape stairs01shape = new PolygonShape(verticesstairs01, 1f);

            stairs01 = new Body(World);
            stairs01.BodyType = BodyType.Static;
            stairs01.Position = new Vector2(500.0f - ConvertUnits.ToSimUnits(512), 50.0f - ConvertUnits.ToSimUnits(288));
            stairs01.CreateFixture(stairs01shape, "stairs01");

And then it look like this http://img17.imageshack.us/img17/8247/dibujoix.png

As you can see, there's a body stuck betewn the "stairs" and the floor. It happens in the middle of the stairs only, becouse it does not collide untill the litthe body is in the middle.

 

Any idea of why does this happen and how to fix it?

Developer
Jul 24, 2011 at 3:07 PM

You need to Decompose your stairs. Concave polygons are not supported.

Jul 24, 2011 at 3:30 PM

Oh thanks. I've used:

List<Vertices> list = BayazitDecomposer.ConvexPartition(verticesstairs01);           

stairs01 = BodyFactory.CreateCompoundPolygon(World, list, 1f, BodyType.Dynamic);

I tought that decomposing my body would make the texture wreid. Now I see it's fine. Thanks.