What i'm trying to do is change the state of my collisionObjects. What i have set up is a falling box whose collisionObject is a btRigidBody (= body) and i want to teleport it around and safely convert between all 3 states.
If i have a dynamic object that i want to 'teleport' and make static i do this:
Code: Select all
dynamicsWorld->removeRigidBody( body );
//teleport
btTransform newTrans = body->getWorldTransform();
newTrans.setOrigin( newLocation );
newTrans.setRotation( newRotation );
body->setWorldTransform( newTrans );
//make static
body->setMassProps( 0.f, btVector3() );
body->setCollisionFlags((body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT));
dynamicsWorld->addRigidBody( body );
Then i want to teleport my static object and make it dynamic again:
Code: Select all
dynamicsWorld->removeRigidBody( body );
//teleport
btTransform newTrans = body->getWorldTransform();
newTrans.setOrigin( newLocation );
newTrans.setRotation( newRotation );
body->setWorldTransform( newTrans );
body->setMassProps( 10.f, btVector3() );
body->activate(true);
body->setLinearVelocity( btVector3(0,0,0) );
body->setAngularVelocity( btQuaternion(0,0,0,1) );
dynamicsWorld->addRigidBody( body );
The problems arise when trying to convert to and from a kinematic state. I use basically the same code as above:
Code: Select all
dynamicsWorld->removeRigidBody( body );
//teleport
btTransform newTrans = body->getWorldTransform();
newTrans.setOrigin( newLocation );
newTrans.setRotation( newRotation );
body->setWorldTransform( newTrans );
//make kinematic
body->setCollisionFlags((body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT));
body->setActivationState(DISABLE_DEACTIVATION);
dynamicsWorld->addRigidBody( body );
Well, any insight is appreciated :]