title: Smooth Rotation using Bullet and Ogre3D
body: <p>I've been suffering from an issue regarding the implementation of orienting characters in a game I'm implementing using Ogre3D and Bullet physics.</p>
  
  <p>What I have: A Direction Vector that the character is moving in, along with its current orientation.</p>
  
  <p>What I need: To set the orientation of the character to face the way it is moving.</p>
  
  <p>I have a snippet of code that sort of does what I want:</p>
  
  <pre><code>btTransform src = body-&gt;getCenterOfMassTransform();
  btVector3 up = BtOgre::Convert::toBullet(Ogre::Vector3::UNIT_X);
  btVector3 normDirection = mDirection.normalized();
  btScalar angle = acos(up.dot(normDirection));
  btVector3 axis = up.cross(normDirection);
  src.setRotation(btQuaternion(axis, angle));
  body-&gt;setCenterOfMassTransform(src);
  </code></pre>
  
  <p>Where 'body' is the rigidbody I'm trying to orient.</p>
  
  <p>This snippet has a couple of problems however:</p>
  
  <p>1) When changing direction, it tends to 'jitter' i.e. it rapidly faces one way, then the opposite for a second or so before correcting itself to the orientation it is supposed to be at.</p>
  
  <p>2) Most times that the code is run I get an assertion error from Bullet's btQuaternion on<br>
  <code>assert(d != btScalar(0.0));</code></p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks!</p>