Polygon created using setVertices causing bodies to stick

Hi guys,

I'm trying to create polygonal platforms in my Android game, but Polygon created using Polygon set(Vec2[], int) causing bodies to stick to it.
Currently I'm using jbox2d-testbed-2.1.2-alpha-v2.jar, which is the latest. I tried it on jbox2d-testbed-2.1.2-alpha.jar but it has the same problem.

Here I create the platform using setAsBox.
Code:
         FixtureDef fd = new FixtureDef();
         PolygonShape sd = new PolygonShape();

//         Vec2 a = new Vec2(-3, -3);
//         Vec2 b = new Vec2(-3, 3);
//         Vec2 c = new Vec2(3, 3);
//         Vec2 d = new Vec2(3, -3);
//         Vec2[] pts = {a, b, c, d};
         
//         sd.set(pts, pts.length);
         
         sd.setAsBox(3, 3);
         
         fd.shape = sd;

         fd.restitution = 0.3f;
         fd.density = 1.0f;
         fd.friction = 0.5f;
                  
         BodyDef bd = new BodyDef();

         bd.position = new Vec2(50, 15);

         Body body = level.m_world.createBody(bd);
         body.createFixture(fd);


From the video, everything's fine.
http://www.youtube.com/watch?v=nv6z8p7MuNs


Here I create it using Polygon set(Vec2[], int).
Code:
         FixtureDef fd = new FixtureDef();
         PolygonShape sd = new PolygonShape();

         Vec2 a = new Vec2(-3, -3);
         Vec2 b = new Vec2(-3, 3);
         Vec2 c = new Vec2(3, 3);
         Vec2 d = new Vec2(3, -3);
         Vec2[] pts = {a, b, c, d};
         
         sd.set(pts, pts.length);
         
//         sd.setAsBox(3, 3);
         
         fd.shape = sd;

         fd.restitution = 0.3f;
         fd.density = 1.0f;
         fd.friction = 0.5f;
                  
         BodyDef bd = new BodyDef();

         bd.position = new Vec2(50, 15);

         Body body = level.m_world.createBody(bd);
         body.createFixture(fd);


As you can see, the red ball is stuck once it touches the middle black box.
The background scrolls at the speed of the red ball, so I know the red ball's velocity is non-zero.
http://www.youtube.com/watch?v=sFSKqms_JSQ


I tried setting enableContinuous to false, but objects just pass through the platform.
http://www.youtube.com/watch?v=riq7e_u0pp8
I think it is because you are defining your vertices in clockwise order. setAsBox does it like this:

m_vertices[0].set(-hx, -hy);
m_vertices[1].set(hx, -hy);
m_vertices[2].set(hx, hy);
m_vertices[3].set(-hx, hy);
Hi Edge,

you're absolutely right! I've changed the order of the vetrtices and now it's working smoothly!


Thanks a lot!

Original thread: https://box2d.org/forum/viewtopic.php?t=7199