I have two objects. A dynamic player and a static ground object.
It was working for a while until I did some refactoring and suddenly my play falls right through my ground object.
Is there anything obviously wrong with the following? I have no idea what might be wrong so if you have experienced this before, enlighten me!
Here's the initialization code of the objects:
(pixelsPerMeter is 10)
int pixelsPerMeter = Game.instance.pixelsPerMeter;
//create body def
BodyDef boxDef = new BodyDef();
boxDef.position.set(0, 0);
boxDef.type = BodyType.DYNAMIC;
//create shape
PolygonShape boxShape = new PolygonShape();
boxShape.setAsBox(this.size.width / pixelsPerMeter, this.size.height / pixelsPerMeter);
//create body
body = Game.instance.world.createBody(boxDef);
//finally create the fixture
FixtureDef boxFixture = new FixtureDef();
boxFixture.density = 1;
boxFixture.shape = boxShape;
//add the fixture to the box? :\
body.createFixture(boxFixture);
This is done twice, one for the player and once for the ground object.
The player's body type is set to BodyType.DYNAMIC while the ground is STATIC.
And of course the ground is below the body, and gravity is set to 9.8f.
this.size.width / pixelsPerMeter
ifthis.size.width
is an integer then the division will be done using integer arithmetic and round towards zero. If it is less than 10 then it will be zero (the same applies to height). \$\endgroup\$