I have a problem with my game in Java with Box2D and LibGDX
I found out that when I use
body.getPosition() it is only half of that of body.getWorldCenter().
The problem here is for me that I use Joints also, which forces me into using body.getPosition().
But now my body gets drawn on the position of body.getWorldCenter().
which makes it so it looks like that
https://i.stack.imgur.com/xsTNl.png
Here is the source code where I create the Car Body
}
public static Body createCarBody(Vector2 position, float sizeX, float sizeY, float density, float friction, float restitution, float linearDamping, float angularDamping)
{
System.out.println("position createCarBody " + position);
Body body = Physics.createBody(createBodyDef(position, linearDamping, angularDamping));
body.createFixture(createFixtureDefCar(createPolygonShape(sizeX, sizeY,position), density, friction, restitution));
return body;
}
public static FixtureDef createFixtureDefCar(PolygonShape shape, float density, float friction, float restitution)
{
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = density;
fixtureDef.friction = friction;
fixtureDef.restitution = restitution;
return fixtureDef;
}
public static PolygonShape createPolygonShape(float sizeX, float sizeY, Vector2 position)
{
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(sizeY/2 , sizeX/2, position,0);
System.out.println("position polygonshape " + position);
return polygonShape;
}
I use the createCarBody method in my car class where it is given a Position Vector of (30,30) ( first car ) and (40,40) second car
If I print body.getWorldCenter() i get (60,60) and (80,80 )