In my application I sometimes need to replace a normal body through a kinematic body, and vice-versa.
I haven't found any method that allows me to do it, so here is actually what I am doing:
Code: Select all
if (pBodyRemoved)
m_pWorld->removeRigidBody(pBodyRemoved);
if (pBodyAdded)
m_pWorld->addRigidBody(pBodyAdded);
if (pBodyRemoved && pBodyAdded)
{
// init body
pBodyAdded->setWorldTransform(pBodyRemoved->getWorldTransform());
pBodyAdded->setInterpolationWorldTransform(pBodyRemoved->getInterpolationWorldTransform());
pBodyAdded->setLinearVelocity(pBodyRemoved->getLinearVelocity());
pBodyAdded->setAngularVelocity(pBodyRemoved->getAngularVelocity());
pBodyAdded->setAngularFactor(pBodyRemoved->getAngularFactor());
pBodyAdded->setDeactivationTime(pBodyRemoved->getDeactivationTime());
pBodyAdded->setActivationState(pBodyRemoved->getActivationState());
}
I would really appreciate if someone could help me on that point.
[EDIT] It seems there is something wrong. First of all, my kinematic object is created with the "DISABLE_DEACTIVATION" flag, so I guess the ActivationState doesn't sync.
My main issue is the following: let's consider two objects having each a normal rigid body. They collide and react.
After some time, both objects don't move anymore (deactivated). At this point I replace the two rigid bodies with kinematic bodies.
However, in the case the objects are for instance one above the other, a collision is detected the next frame and both objects are thrown away (big reaction in other word). Any idea what happens ?
Cheers,
Gregory