Destroying fixtures

Hi!

I'm using Box2d to create a 2D-physics game.
The pieces in the game consists of a couple of fixtures attached to a body and sometimes a few fixtures should be removed and the piece should break.
For example lets say I have a piece that looks like this: OOOO and this fixture should disappear: OXOO two new bodies will be created, one looking like O and one looking like OO.

Well that part works (splitting the bodies) except for a minor problem. Sometimes a piece will move and get stuck in another piece and the game will break.
I do not know if this is because the piece actually moves or if the engine just doesn't like me placing bodies so close.
Anyway, here's the code for creating new bodies:

Code:
// body - The old body which will be splitted
// fixtures - contains all the fixtures that should belong to the same body
b2BodyDef newBodyDef;
newBodyDef.userData = FALLING;
newBodyDef.type = b2_dynamicBody;
newBodyDef.position = body->GetPosition();
b2Body *newBody = world -> CreateBody(&newBodyDef);

// Attach the fixtures to the new body
foreach(fix, fixtures) {
   b2PolygonShape s;
   b2Vec2 tmp = fGetCenter(*fix);
   tmp.x -= 0.5f;
   tmp.y -= 0.5f;
   s.SetAsBox(0.5f, 0.5f, tmp, 0.0f);
   b2Fixture *newFix = newBody -> CreateFixture(&s, 1.0f);
   newFix -> SetRestitution(0.2f);
   newFix -> SetUserData((*fix)->GetUserData());
   body->DestroyFixture(*fix);
}


Is there a better way of doing this or have I simply overlooked something?

Best Regards
Nicklas
For simplicity I would keep both bodies at the position of the original body. In this case the fixture geometry should not be shifted.
How do you mean?
I need to create two new bodies as the fixtures should go their separate ways. Could the problem be that the bodies have the same position (even though the bodies never overlap)?
No, I'm telling you to remove these lines:
Code:
tmp.x -= 0.5f;
   tmp.y -= 0.5f;


Create both bodies at the same position as the original body and use the exact same numbers to create the fixtures.
Well actually that is right way as I increase the values by 0.5 when i create the bodies (without the jump is very noticable).
It turns out that the problem is because I didn't copy the angle 🙂
I just added this line and it worked:
Code:
newBodyDef.angle = body->GetAngle();


That's for the quick replies though 🙂
Yup, that will do it. 🙂
Though sometimes (VERY rare) the pieces will jump trough the floor and get caught in each other it seems, is there anything else I might have missed to copy?

Original thread: https://box2d.org/forum/viewtopic.php?t=5292