Unexpected rotation when rotation limited to Y Axis

EmoryM
Posts: 4
Joined: Sun Oct 02, 2011 10:07 am

Unexpected rotation when rotation limited to Y Axis

Post by EmoryM »

Thrilled with Bullet so far, but in developing a character creator I hit upon a strange issue. I searched around the boards, and found something about angular friction but I'm not sure if it was relevant. I'm assuming this has already been presented/solved and I just haven't hit upon the right post, hopefully this won't waste too much of your time!

When using either:

Code: Select all

rigidBody->setAngularFactor( btVector3( 0.0f, 1.0f, 0.0f ) );
or

Code: Select all

btVector3 tensor = rigidBody->getInvInertiaDiagLocal();
tensor.setX( 0.0f );
tensor.setZ( 0.0f );
rigidBody->setInvInertiaDiagLocal( tensor );
rigidBody->updateInertiaTensor();
and applying a force using

Code: Select all

btVector3 position = it->rigidBody->getWorldTransform().getOrigin();
target.setY( position.getY() );
btVector3 localDir = ( target - position ).normalized();
btVector3 force = btVector3( localDir.getX() * 40.0f, 0.0f, localDir.getZ() * 40.0f );
it->rigidBody->applyCentralForce( force );
the object rotates unexpectedly while moving, and sometimes continues to rotate instead of coming to rest.

A video of the problem: http://www.youtube.com/watch?v=z7Y4NOktCfE
And without limiting to Y-axis rotation: http://www.youtube.com/watch?v=kJfXJKMYAR0

Just noticed I inadvertently added a soundtrack, lol. Let me know if more code helps, the setup is basically mimicking the helloworld example. The friction on the plane and box shapes is 1.0.