<solved> clear PhysicsSpace

Hi guys,



does anybody know how to clear the PhysicsSpace in jbullet-jme with jme2 without recreate?



My problem is that I have an editor in which I can enable o disable the physics. When the physics are disabled the objects are placed on the position before enabling the physics but the PhysicsSpace keeps the motion of some objects and doesn’t begin the update at the new/old position. But it isn’t on all objects, only on a few.

Just remove all physics objects from the physicsspace…

I do this. Remove it, replace it, update bounds and Renderstate and add it.

then call clearForces() on the physicsnodes

directly on the physicsnodes? cause I’ve tried it at the dynamicsworld and there it doesn’t matter.

Yes. You should not use the com.bulletphysics objects directly, they will not be there anymore when physics moves to native bullet. When the javadoc says “used internally” dont use that method.

no, that doesn’t helps. It’s very curious because the problem only happens when the object finished the motion. Like a box is falling down a mountain. When I stop the physic while the box is falling and restart it, the box is falling from the original point again but when I stop the physic and the box isn’t falling anymore it remains on the last point of the motion.



Here is my code where I reset the objekts.

[java]public void zuruecksetzen(Node root, Node zweite)

{

for(int v=0;v<root.getQuantity();v++)

{

if(root.getChild(v) instanceof Node &&!(root.getChild(v) instanceof PhysicsNode)&&!(root.getChild(v) instanceof PhysicsVehicleNode))

{

zuruecksetzen((Node)root.getChild(v), (Node)zweite.getChild(v));

}

else

{

if(root.getChild(v).getName().contains(“Physic”))

{

pSpace.remove(root.getChild(v));

((PhysicsNode)root.getChild(v)).clearForces();



}



root.getChild(v).setLocalRotation(zweite.getChild(v).getLocalRotation().clone());

root.getChild(v).setLocalScale(zweite.getChild(v).getLocalScale().clone());

root.getChild(v).setLocalTranslation(zweite.getChild(v).getLocalTranslation().clone());

root.getChild(v).updateModelBound();

root.getChild(v).updateWorldBound();

root.getChild(v).updateRenderState();

if(root.getChild(v).getName().contains(“Physic”))

{

pSpace.add(root.getChild(v));

}



}

}

}

[/java]



zweite is my reference node where the position, rotation, etc is stored from befor the physics are enabled.

How do you enable/disable physics anyway? Theres no switch for it. Btw, “curious” means “neugierig” not “kurios” :wink:

in the simpleUpdate() I look if the “Physicsbutton” is pressed and when it’s true then is calling PhysicsSpace.update(tpf) else it will not update. And I looked for the word “merkwürdig” and there was “curious” suggested. :slight_smile:

I suggest strange, fits normally everywhere ^^

When the physicsspace is not updated the physics nodes are not updated.

but why it works when I stop it in the motion?

So, it’s a long time ago but maybe somebody has the same problem. I found the solution:



If a physicsNode has done his motion, his activate-status is false, as long as no other physicsNode has a collision with it.

Activate the physicsNode again solved my problem.



[java]

((PhysicsNode)root.getChild(v)).activate();

((PhysicsNode)root.getChild(v)).clearForces();

[/java]