Hi there
i have a player object defined by a polygon:
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
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