Destroying Scene Nodes And Entites on Body Leave

nickgravelyn

18-06-2007 23:20:22

I'm trying to program OgreNewt to destroy scene nodes when the bodies leave the physics world. My attempt works for a bit, but then I get an exception after a while. Any ideas?

void CubismApp::bodyLeaveWorld(OgreNewt::Body* bod)
{
Node *node = bod->getOgreNode();
mSceneMgr->destroySceneNode(node->getName());
}

walaber

19-06-2007 00:29:06


void CubismApp::bodyLeaveWorld(OgreNewt::Body* bod)
{
Node *node = bod->getOgreNode();
if (node)
{
mSceneMgr->destroySceneNode(node->getName());
bod->attachToNode( NULL );
}
}


note that you should probably delete the body itself as well, otherwise you will have an invisible physics body "stuck" at the edge of your physics world somewhere :)