Polygon gets stuck

Hi there

i have a player object defined by a polygon:

Code:

      BodyDef bodyDef = new BodyDef();
      bodyDef.type = BodyType.DYNAMIC;
      bodyDef.position.set(getWorldX(startX*tileWidth+tileWidth/2), getWorldY(startY*tileHeight));
      bodyDef.linearDamping=0.6f;
      bodyDef.angularDamping=0.0f;

      playerBody = world.createBody(bodyDef);
      playerBody.setFixedRotation(true);
      playerPolygon = new PolygonShape();

      // playerPolygon.setAsBox(getWorldX(tileWidth/2), getWorldY(tileHeight/2-2));

      Vec2 vertices[] = new Vec2[8];
      vertices[0] = new Vec2(getWorldX(1-tileWidth/2), getWorldY(21-tileHeight/2-4));
      vertices[1] = new Vec2(getWorldX(12-tileWidth/2), getWorldY(28-tileHeight/2-4));
      vertices[2] = new Vec2(getWorldX(52-tileWidth/2), getWorldY(28-tileHeight/2-4));
      vertices[3] = new Vec2(getWorldX(62-tileWidth/2), getWorldY(21-tileHeight/2-4));
      vertices[4] = new Vec2(getWorldX(52-tileWidth/2), getWorldY(9-tileHeight/2-4));
      vertices[5] = new Vec2(getWorldX(32-tileWidth/2), getWorldY(1-tileHeight/2-4));
      vertices[6] = new Vec2(getWorldX(10-tileWidth/2), getWorldY(9-tileHeight/2-4));
      vertices[7] = new Vec2(getWorldX(10-tileWidth/2), getWorldY(9-tileHeight/2-4));
      playerPolygon.set(vertices, 8);

      FixtureDef fixtureDef = new FixtureDef();
      fixtureDef.shape = playerPolygon;
      fixtureDef.density = 5.0f;
      fixtureDef.friction = 0.2f;
      fixtureDef.restitution = 0.3f;
      playerBody.createFixture(fixtureDef);


I apply forces to the player depending on the keyboard input. If i use the polygon created by the vertices, as soon as the player hits anything, it does not react to any forces anymore, it is as if it either went to sleep and refuses to get awake, or it is simply stuck (the colliding objects are simple polygon shapes created with setAsBox())

If replace the vertice part with the setAsBox() from above, which is commented out, it works.

What could be the reason?

Thank you
Please read in the FAQ about tile based environments: http://code.google.com/p/box2d/wiki/FAQ

In 2.2 you can use edge chains to avoid these internal collisions.
hi and thanx, my problem is not (yet) that i am running tilebased, it is that shape.set(vertices) gets stuck immediately where ever it touches, whereas shape.setAsBox() does not.

I have attached a screenshot, the spaceship was going straight upward without side movement and then got stuck. With a restitution of 0.3 and gravity pointing downward, this should never happen in this situation, or am i wrong?
Oh, I think this problem is due to the winding order of the polygon. I'm putting out a new version of Box2D C++ soon that prevents this problem by computing the convex hull. Look for that in 2.3.

In your case you probably just need to reverse the order of the polygon vertices.
Problem solved, although it's a bit confusing, manual says, that polygons need to be counter clock wise, now i have a clock wise polygon. Anyway, whatever works. Thank you.

*edit* ah, i forgot, that i am actually cheating and actually have the whole world upside down, as my level editor has Y pointing downward, so it actually was a clock wise polygon... these axis keep tricking me 😉

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