Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been suffering from an issue regarding the implementation of orienting characters in a game I'm implementing using Ogre3D and Bullet physics.

What I have: A Direction Vector that the character is moving in, along with its current orientation.

What I need: To set the orientation of the character to face the way it is moving.

I have a snippet of code that sort of does what I want:

btTransform src = body->getCenterOfMassTransform();
btVector3 up = BtOgre::Convert::toBullet(Ogre::Vector3::UNIT_X);
btVector3 normDirection = mDirection.normalized();
btScalar angle = acos(;
btVector3 axis = up.cross(normDirection);
src.setRotation(btQuaternion(axis, angle));

Where 'body' is the rigidbody I'm trying to orient.

This snippet has a couple of problems however:

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.

2) Most times that the code is run I get an assertion error from Bullet's btQuaternion on

assert(d != btScalar(0.0));

Can anyone help?


share|improve this question

closed as too localized by Josh Petrie, Sean Middleditch, Byte56, Laurent Couvidou, bummzack Feb 27 '13 at 22:52

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

This assert sounds like an attempt to normalize a null quaternion, which makes no sense mathematically (it's essentially a divide by zero). You should fire your debugger and navigate the callstack to spot the error. We can't find the exact answer for you, you need to learn how to use the tools for the job. That said, this question is probably too localized for this site, check the faq for details. – Laurent Couvidou Feb 27 '13 at 15:30