Make existing static/kinematic body behave like dynamic one

B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Make existing static/kinematic body behave like dynamic one

Post by B_old »

Hi,
I would like to make an existing (already added to the simulation) static or kinematic shape behave like a dynamic one at a certain point. Here is what I tried:

Code: Select all

float mass = 500.0f;

btVector3 localInertia(btScalar(0), btScalar(0), btScalar(0));

m_body->getCollisionShape()->calculateLocalInertia(btScalar(mass), localInertia);

m_body->setMassProps(mass, localInertia);

m_body->setCollisionFlags(0);

m_body->setGravity(btVector3(btScalar(0), btScalar(-9.8), btScalar(0)));

m_body->forceActivationState(0);
m_body->activate();
One problem I have, is that the body will only collide with dynamic bodies but not with static/kinematic ones. Didn't I fix that with the collisionflags?
Also I wonder about the gravity. Is there an elegant way to give the body the same gravity as specified in the dynamicsWorld? I haven't yet checked how bullet handles gravity. Maybe if I manually set the gravity for all (dynamic/kinematic/static) bodies when I add them to the world it won't change their behavior but they will automatically have the gravity ready once they become dynamic. What do you think?

Thanks for any help.
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Make existing static/kinematic body behave like dynamic one

Post by pico »

Hi,

you need to remove and add again the body to make it work.

bltWorld->removeCollisionObject(body);
.. do your stuff here ..
bltWorld->addRigidBody(body,filterGroup,filterMask);

regards
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Make existing static/kinematic body behave like dynamic one

Post by B_old »

pico wrote:Hi,

you need to remove and add again the body to make it work.

bltWorld->removeCollisionObject(body);
.. do your stuff here ..
bltWorld->addRigidBody(body,filterGroup,filterMask);

regards
I almost thought so. Is that the only way to do it? Would have preferred it otherwise, but I can live with it. I suppose, that would solve my gravity problem though. Thanks for the help!

I have another question about the mass. Static/Kinematic objects have a mass of 0. But when I make them dynamic I need a mass. That mass is read from a file during scene creation time. So when I make a body dynamic, I either have to read it again (not an option) or I have to store it somewhere. Could I store it in the btRigidBody regardless of kinematic/dynamic behavior or will setting a mass != 0 always make the body dynamic? It would only save me one float, but still.