Box2d polygon box doesn't collide accurately. I use Box2ddebug renderer and reused Polygonshape several times. When boxshape is on a ground body (static) there is a gap between these bodies. Can anyone help me with this?
public class BoxShape extends Shape implements ShapeAccessor {
private DotShape a, b, c, d;
private Rectangle rect;
private Vector2 temp = new Vector2();
private float hw = 0, hh = 0;
public BoxShape(float x, float y, float u, float v) {
a = new DotShape(x, y, this);
b = new DotShape(u, y, this);
c = new DotShape(u, v, this);
d = new DotShape(x, v, this);
hw = u - x;
hh = y - v;
rect = new Rectangle(d.getX(), d.getY(), hw, hh);
rect.getCenter(temp);
center = new DotShape(temp.x, temp.y, this);
center.setColor(Color.MAGENTA);
bodyDef.position.set(temp.x * Assets.ws, temp.y * Assets.ws);
this.setColor(Color.BLUE);
}
@Override
public Body createBody(World world) {
Body b = world.createBody(bodyDef);
b.setUserData(new Data(getName()));
return b;
}
@Override
public Fixture createFixture(Body body) {
Assets.p.setAsBox(((rect.width / 2) * Assets.ws),
((rect.height / 2) * Assets.ws));//ws does scaling. world ranges from 0.1 to 20 meter
fixtureDef.shape = Assets.p;
return body.createFixture(fixtureDef);
}
........................
........................
Then the bodies and fixture are made by:
public void createWorld(World world) {
for (Shape s : shapes) {
Body b=s.createBody(world);
s.createFixture(b);
}
for (JointShape j : joints) {
j.createJoint(world);
}
}