title: Re-positioning a Rigid Body in Bullet Physics
body: <p>I am writing a character animation rendering engine that uses Bullet Physics as a physics simulation engine.</p>
  
  <p>A sequence will start out with no model on the screen, then an animation will be assigned to that model, the model will be moved to frame 0 of the animation, and the engine will begin rendering the model with the animation.</p>
  
  <p>What is the correct way to re-position the rigid bodies on the character model when it is initialized at frame 0?</p>
  
  <p>Currently I am using this code, which is called immediately after the animation is assigned to the model and the bones are moved to the frame 0 position:</p>
  
  <pre><code>_world-&gt;removeRigidBody(_body);
  bool k = (_type == Kinematics);
  _body-&gt;setCollisionFlags(_body-&gt;getCollisionFlags() &amp; ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
  btTransform tr = BulletPhysics::ConvertD3DXMatrix(&amp;(_bone-&gt;getCombinedTrans()));
  tr *= _trans;
  _body-&gt;setCenterOfMassTransform(tr);
  _body-&gt;clearForces();
  _body-&gt;setLinearVelocity(btVector3(0,0,0));
  _body-&gt;setAngularVelocity(btVector3(0,0,0));
  _world-&gt;addRigidBody(_body, _groupID, _groupMask);
  </code></pre>
  
  <p>The issue is that sometimes this works, and other times not. For an example, take a skirt of a model. Sometimes it will show up in the natural position, other times slightly misaligned and it will fall into place, and other times it shows up completely clipped through the body, as if collision was turned off and some force pushed it in that direction. This does make sense most of the time, because in the test animation I am using the model's initial position is in the center of the screen, but the animation starts off the left side of the screen. Does anyone know how to solve this?</p>
  
  <p>I know the bones on the skirt are not the problem, because I turned off physics and forced it to manually update the bone positions each frame, and everything was in the correct positions throughout the entire animation.</p>
  
  <p>EDIT: I also have constraints, might that be what's causing this?</p>