Jaitnium Jaitnium - 4 months ago 20
C++ Question

Bullet | Rigidbody translated correctly but printed position is wrong

I have a very simple problem, but I can't see what I'm doing wrong.

I have a rigidbody starting at pos: 0.0, 3.0, 0.0. I apply a translate, -90 degree rotation, and then another translate. The rigidbody's final position should be 2.0, 1.0, 0.0, but the position that is printed out is still 0.0, 3.0, 0.0.

I perform a collision test by dropping some small cubes above the rigidbody in question. Oddly enough, they stop above 2.0, 1.0, 0.0 showing that the rigidbody was moved correctly.

//Rigidbody in question
btRigidBody *btPhys;

//First transform
btPhys->translate(btVector3(0.0, -2.0, 0.0));

//Perform -90 degree rotation
btMatrix3x3 orn = btPhys->getWorldTransform().getBasis();
orn *= btMatrix3x3(btQuaternion( btVector3(0, 0, 1), btScalar(degreesToRads(-90))));

//Perform second transform
btPhys->translate(btVector3(2.0, 0.0, 0.0));

//Print out final position
btTransform trans;
float x, y, z;
x = trans.getOrigin().getX();
y = trans.getOrigin().getY();
z = trans.getOrigin().getZ();

printf("\n\nposition: %f %f %f\n\n", x, y, z);

Basically, I'd just like to be able to get the correct position of the rigidbody from this code (2.0, 1.0, 0.0). Thank you!


In your case, if you want to obtain correct position of btRigidBody you should call:


You are calling


instead, but the MotionState is not yet updated. All MotionStates are updated in simulation step.