2
\$\begingroup\$

I'm creating my first libgdx / Box2D game where a player moves around using a mouseJoint.

My player has two fixtures, "main" and "question".

For some reason when I have these two fixtures, my player is no longer responsive to collisions or touch detection (i.e. I can't drag the player around). If I remove the "question" fixture, everything works.

Why is this? How can I fix it?


This is how I create the Player:

// create body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(x, y);
bodyDef.fixedRotation = true;
body = world.createBody(bodyDef);

// player main body fixture
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(bodyWidth / 2, bodyHeight / 2); // setAsBox takes half width, half height as params
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = polygonShape;
fixtureDef.restitution = 0.3f; // Bounciness - Keep value between 0 and 1.
fixtureDef.density = 3; // Mass p/sqm - Keep value between 0 and 100
fixtureDef.friction = 0.8f; // Slippery - Keep value between 0 and 1
bodyFixture = body.createFixture(fixtureDef);
bodyFixture.setUserData("player");

// player question fixture
polygonShape = new PolygonShape();
polygonShape.setAsBox(questionWidth / 2, questionHeight / 2, new Vector2(0,0), 0); // setAsBox takes half width, half height as params
fixtureDef.shape = polygonShape;
fixtureDef.restitution = 0.3f; // Bounciness - Keep value between 0 and 1.
fixtureDef.density = 3; // Mass p/sqm - Keep value between 0 and 100
fixtureDef.friction = 0.8f; // Slippery - Keep value between 0 and 1
fixtureDef.friction = 0.8f; // Slippery - Keep value between 0 and 1
fixtureDef.isSensor = true;
questionFixture = body.createFixture(fixtureDef);
questionFixture.setUserData("question");

I assume I'm doing something silly here—I'm still very much a noob when it comes to libgdx / Box2D.

\$\endgroup\$
  • \$\begingroup\$ You don't specify any translations for the Shapes, is it intentional that the Fixtures overlap with the bigger completely covering the smaller? \$\endgroup\$ – bornander Dec 17 '14 at 9:08
  • \$\begingroup\$ i moved the shapes over each other just for testing, i had them apart earlier - of course that made no difference. \$\endgroup\$ – ParampalP Dec 17 '14 at 9:40
  • 1
    \$\begingroup\$ You got the debug-renderer turned on, right? Does everything look Ok or is something visually out of place? \$\endgroup\$ – bornander Dec 17 '14 at 10:02
  • \$\begingroup\$ @bornander yep debug renderer is on and everything looks fine \$\endgroup\$ – ParampalP Dec 17 '14 at 10:47
  • \$\begingroup\$ No contact filters are active, or are you setting up mask bits somewhere for the body/fixture categories? \$\endgroup\$ – bornander Dec 17 '14 at 11:34
1
\$\begingroup\$

Well on your question fixture def, you set sensor true which makes it ignore collisions.

fixtureDef.isSensor = true;

Unrelated but as a side note, I think you need to dispose your polygonShape at the end after creating everything.

polygonShape.dispose()
\$\endgroup\$
  • \$\begingroup\$ I tried changing isSensor to false and it didn't fix it. And yep, i just omitted the dispose() call. \$\endgroup\$ – ParampalP Dec 17 '14 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.