When I add multiple fixtures to a single body using Box2D, the body rotates around the centre point of the first fixture (polygon), instead of the centre point of the body (0,0). Imagine like this:
The centre point of the shape is (0, 0). How can I make it so that it rotates around the true centre point instead of the centre of the first fixture?
Some of the code I have right now:
//create body def
let shape = collider.mesh;
let position = collider.gameObject.transform.position;
let bodyDef = new Box2DBodyDef(bodyType, position, options);
let shapeCount = shape.PointSets.length;
let box2DShapes = Array<b2Shape>(shapeCount);
let b2Body = this._b2world.CreateBody(bodyDef.box2DBodyDef);
for (let i = 0; i < shapeCount; i++) {
let b2Shape = new b2PolygonShape();
let polygon: Vector2[];
polygon = shape.GetScaledPoints(collider.gameObject.transform.scale)[i]; // scales points
b2Shape.Set(polygon);
box2DShapes[i] = b2Shape;
}
//create box2D fixtures
for (let i = 0; i < box2DShapes.length; i++) {
let fixture = new b2FixtureDef();
fixture.shape = box2DShapes[i];
fixture.density = options.densityValues[i];
fixture.friction = options.frictionValues[i];
fixture.restitution = options.resitutionValues[i];
b2Body.CreateFixture(fixture);
}
//make Box2DBody
let body = new Box2DBody(b2Body, new ID().ID, bodyType);