I have a game where the user controls a box to collect falling balls. However, very often the balls will just fall through the walls of the box and be flung away. What could be causing the balls to do that?
Here is a video of the issue.
Here’s how I’m creating the box and the balls:
//BOX CODE
private Body pbox() {
pbdef = new BodyDef();
PolygonShape shape=new PolygonShape();
pbdef.type=BodyType.StaticBody;
pbdef.position.set(Gdx.graphics.getWidth()/2,100);
Body body1=world.createBody(pbdef);
FixtureDef fdef = new FixtureDef();
shape.setAsBox(30, 5);
fdef.shape=shape;
fdef.density=1;
fdef.friction=0.5f;
body1.createFixture(fdef);
//
shape.setAsBox(5, 20,new Vector2(-25,15),0);
fdef.shape=shape;
fdef.density=1;
fdef.friction=0.5f;
body1.createFixture(fdef);
fdef = new FixtureDef();
//
shape.setAsBox(5, 20,new Vector2(25,15),0);
fdef.shape=shape;
fdef.density=1;
fdef.friction=0.5f;
body1.createFixture(fdef);
body1.setGravityScale(-3);
body1.setBullet(true);
return body1;
}
//BALLS CODE
private void spawner() {
bbdef= new BodyDef();
FixtureDef fdef = new FixtureDef();
CircleShape circle = new CircleShape();
bbdef.type=BodyType.DynamicBody;
bbdef.position.set(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight());
bbody = world.createBody(bbdef);
circle.setRadius(5);
fdef.shape=circle;
fdef.density=0;
fdef.friction=0;
bbody.createFixture(fdef).setUserData("ball");
bbody.setBullet(true);
}