KennyUK
16-04-2008 16:29:14
In my platform game, I need to reset all active bodies to an initial state when my character dies, so they can try again. I can save the position and orientation of all active bodies to the ogre scenenode when the level is loaded and when my character dies I call the following code on all active bodies:
I tested it using a stack of boxes, knocking them over in the game and then reseting the level, and it appears to work most of the time. However, sometimes after the level has been reset when I knock the boxes over they can get stuck in midair, rather than falling. Is there any more physics state that I have to reset? I have tried doing setAutoFreeze(0) for all these objects but it still seems to happen.
Any ideas?
for(a_it = active_objects.begin(); a_it != active_objects.end(); a_it++)
{
OgreNewt::Body *bod = (*a_it);
Ogre::Vector3 init_pos = bod->getOgreNode()->getInitialPosition();
Ogre::Quaternion init_orient = bod->getOgreNode()->getInitialOrientation();
bod->setVelocity(Ogre::Vector3::ZERO);
bod->setOmega(Ogre::Vector3::ZERO);
bod->setPositionOrientation(init_pos, init_orient);
}
I tested it using a stack of boxes, knocking them over in the game and then reseting the level, and it appears to work most of the time. However, sometimes after the level has been reset when I knock the boxes over they can get stuck in midair, rather than falling. Is there any more physics state that I have to reset? I have tried doing setAutoFreeze(0) for all these objects but it still seems to happen.
Any ideas?