Dynamic to Kinematic to Static, etc.

iZiMO
Posts: 7
Joined: Thu Jul 31, 2008 11:31 pm

Dynamic to Kinematic to Static, etc.

Post by iZiMO »

Hey guys,

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 );
right? Now this works fine.

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 );
All good. The object teleports and starts falling in it's new location.

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 );
Unfortunately this isn't working. My object flickers to it's new location then back to the position it was in at the last physics step. I'm also unsure of the process to convert this kinematic object back to a dynamic one. Simply using the same 'static to dynamic' code above has same flickering effect. I assume i have to 'un-set' the CF_KINEMATIC_OBJECT flag somehow?

Well, any insight is appreciated :]
iZiMO
Posts: 7
Joined: Thu Jul 31, 2008 11:31 pm

Re: Dynamic to Kinematic to Static, etc.

Post by iZiMO »

C'mon guys :P

There's gotta be a standard way of converting to and from the Kinematic state that i'm missing :/