I want to change a spatial from static node to dynamic node (with jmePhysic2).
I have this hierarchy:
StaticNode-Node-Container (It's the container I want to change to dynamic)
Support
When container become dynamic, instead of staying at is place waiting for a force to move it, it goes nowhere and turn arownd himself.
It seems static node physicbounds does not refesh.
Is it a bug or i forgot to call a refresh methods (which one ?)?
Here an example code.
Wait 5 secondes to see the change :
package tests.statictodynamic;
import com.acarter.scenemonitor.SceneMonitor;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.util.SimplePhysicsGame;
public class StaticToDynamic extends SimplePhysicsGame{
boolean activa = true;
boolean activa1 = false;
StaticPhysicsNode staticNode;
Box visualFallingBox;
Node n = null;
protected void simpleInitGame() {
staticNode = getPhysicsSpace().createStaticNode();
rootNode.attachChild( staticNode );
n = new Node("StaticNode");
final Box visualFloorBox = new Box( "floor", new Vector3f(), 5, 0.25f, 5 );
//staticNode.attachChild( visualFloorBox );
visualFallingBox = new Box( "falling box", new Vector3f(), 0.5f, 0.5f, 0.5f );
visualFallingBox.getLocalTranslation().set( 0, 1f, 0 );
//staticNode.attachChild(visualFallingBox);
n.attachChild(visualFloorBox);
n.attachChild(visualFallingBox);
staticNode.attachChild(n);
staticNode.generatePhysicsGeometry();
SceneMonitor.getMonitor().showViewer(true);
SceneMonitor.getMonitor().registerNode(rootNode);
}
@Override
protected void simpleUpdate() {
SceneMonitor.getMonitor().updateViewer(timer.getTimeInSeconds());
if((activa)&&((timer.getTimeInSeconds()>5))){
System.out.println("Start");
//Remove static node :
staticNode.detachChild(visualFallingBox);
DynamicPhysicsNode dynamicNode = getPhysicsSpace().createDynamicNode();
dynamicNode.setAffectedByGravity(false);
rootNode.attachChild( dynamicNode );
dynamicNode.attachChild( visualFallingBox );
dynamicNode.generatePhysicsGeometry();
activa=false;
activa1=true;
}
}
/**
* The main method to allow starting this class as application.
*
* @param args command line arguments
*/
public static void main( String[] args ) {
new StaticToDynamic().start();
}
}