Can someone explain me the problem, please?
Force is 0,0,0 and Gravity is false…why does the box still move?
box.setAffectedByGravity(false);
Any suggestion?
Not enough info provided, ideally it would be nice to have a test case to see exactly what you are talking about…
This is the code;
package game.bin.app;
import game.GameClass;
import game.bin.view.CameraClass;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.material.Material;
public class TestApp extends Node{
public TestApp(String name){
super(name);
System.out.println("Test Class Created");
runApp();
}
public void runApp(){
Box bb=new Box("My Box",new Vector3f(), 10, 0.2f, 10);
// Give the box a bounds object to allow it to be culled
bb.setModelBound(new BoundingSphere());
// Calculate the best bounds for the object you gave it
bb.updateModelBound();
// Move the box 2 in the y direction up
bb.setLocalTranslation(new Vector3f(0,-5,0));
// Give the box a solid color of blue.
bb.setDefaultColor(ColorRGBA.blue.clone());
Box bbb=new Box("My Box",new Vector3f(0,0,0), 20, 0.2f, 20);
// Give the box a bounds object to allow it to be culled
bbb.setModelBound(new BoundingSphere());
// Calculate the best bounds for the object you gave it
bbb.updateModelBound();
// Move the box 2 in the y direction up
bbb.setLocalTranslation(new Vector3f(0,-10,0));
// Give the box a solid color of blue.
bbb.setDefaultColor(ColorRGBA.green.clone());
/*Sphere s=new Sphere("My sphere",10,10,1f);
// Do bounds for the sphere, but we'll use a BoundingBox this time
s.setModelBound(new BoundingBox());
s.updateModelBound();
// Give the sphere random colors
s.setRandomColors();*/
// Make a node and give it children
Node n=new Node("My Node");
n.attachChild(bb);
n.attachChild(bbb);
//n.attachChild(s);
// Make the node and all its children 5 times larger.
/*Box wall = new Box(name, new Vector3f(0,0,0),10,0.2f,10);
wall.setModelBound(new BoundingBox());
wall.updateModelBound();
StaticPhysicsNode physicWall = GameClass.getPhysicsSpace().createStaticNode();
physicWall.attachChild(wall);
physicWall.getLocalTranslation().set(0, -8, 0);
//physicWall.setLocalTranslation(new Vector3f(0,-8,0));
physicWall.generatePhysicsGeometry();
wall.setDefaultColor(ColorRGBA.red.clone());
n.attachChild(wall);*/
// Remove lighting for rootNode so that it will use our basic colors.
//this.setLightCombineMode(Spatial.LightCombineMode.Off);
Box b = new Box("box", new Vector3f(), 1, 1, 1);
b.setModelBound(new BoundingBox());
b.updateModelBound();
b.setLocalTranslation(new Vector3f(0,10,0));
DynamicPhysicsNode box = GameClass.getPhysicsSpace().createDynamicNode();
box.setName("physics");
box.attachChild(b);
box.generatePhysicsGeometry();
box.setMaterial(Material.IRON);
box.computeMass();
box.setMass(1000);
box.setAffectedByGravity(false);
System.out.println(box.isAffectedByGravity() + " " + box.getMass() + " " + box.getForce(null));
n.attachChild(box);
Box wallb = new Box("box", new Vector3f(), 10, 0.2f, 10);
wallb.setModelBound(new BoundingBox());
wallb.updateModelBound();
wallb.setLocalTranslation(new Vector3f(0,-15,0));
StaticPhysicsNode wall = GameClass.getPhysicsSpace().createStaticNode();
wall.setName("physics");
wall.attachChild(wallb);
wall.generatePhysicsGeometry();
wall.setMaterial(Material.IRON);
//wall.computeMass();
n.attachChild(wall);
//n.setLocalScale(5);
this.attachChild(n);
System.out.println("Test Class Added");
}
}
Maybe the problem is the first frame, because somehow the physics react crazy the first moments and my box gets a supernatural force^^
Probably something with your physics…
This works fine (top box doesn't move at all)…
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
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.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;
public class gravTest extends SimplePhysicsGame {
public static void main( String[] args ) {
new gravTest().start();
}
public void simpleInitGame(){
Box bb=new Box("My Box",new Vector3f(), 10, 0.2f, 10);
// Give the box a bounds object to allow it to be culled
bb.setModelBound(new BoundingSphere());
// Calculate the best bounds for the object you gave it
bb.updateModelBound();
// Move the box 2 in the y direction up
bb.setLocalTranslation(new Vector3f(0,-5,0));
// Give the box a solid color of blue.
bb.setDefaultColor(ColorRGBA.blue.clone());
Box bbb=new Box("My Box",new Vector3f(0,0,0), 20, 0.2f, 20);
// Give the box a bounds object to allow it to be culled
bbb.setModelBound(new BoundingSphere());
// Calculate the best bounds for the object you gave it
bbb.updateModelBound();
// Move the box 2 in the y direction up
bbb.setLocalTranslation(new Vector3f(0,-10,0));
// Give the box a solid color of blue.
bbb.setDefaultColor(ColorRGBA.green.clone());
/*Sphere s=new Sphere("My sphere",10,10,1f);
// Do bounds for the sphere, but we'll use a BoundingBox this time
s.setModelBound(new BoundingBox());
s.updateModelBound();
// Give the sphere random colors
s.setRandomColors();*/
// Make a node and give it children
Node n=new Node("My Node");
n.attachChild(bb);
n.attachChild(bbb);
//n.attachChild(s);
// Make the node and all its children 5 times larger.
/*Box wall = new Box(name, new Vector3f(0,0,0),10,0.2f,10);
wall.setModelBound(new BoundingBox());
wall.updateModelBound();
StaticPhysicsNode physicWall = GameClass.getPhysicsSpace().createStaticNode();
physicWall.attachChild(wall);
physicWall.getLocalTranslation().set(0, -8, 0);
//physicWall.setLocalTranslation(new Vector3f(0,-8,0));
physicWall.generatePhysicsGeometry();
wall.setDefaultColor(ColorRGBA.red.clone());
n.attachChild(wall);*/
// Remove lighting for rootNode so that it will use our basic colors.
//this.setLightCombineMode(Spatial.LightCombineMode.Off);
Box b = new Box("box", new Vector3f(), 1, 1, 1);
b.setModelBound(new BoundingBox());
b.updateModelBound();
b.setLocalTranslation(new Vector3f(0,10,0));
DynamicPhysicsNode box = getPhysicsSpace().createDynamicNode();
box.setName("physics");
box.attachChild(b);
box.generatePhysicsGeometry();
box.setMaterial(Material.IRON);
box.computeMass();
box.setMass(1000);
box.setAffectedByGravity(false);
System.out.println(box.isAffectedByGravity() + " " + box.getMass() + " " + box.getForce(null));
n.attachChild(box);
Box wallb = new Box("box", new Vector3f(), 10, 0.2f, 10);
wallb.setModelBound(new BoundingBox());
wallb.updateModelBound();
wallb.setLocalTranslation(new Vector3f(0,-15,0));
StaticPhysicsNode wall = getPhysicsSpace().createStaticNode();
wall.setName("physics");
wall.attachChild(wallb);
wall.generatePhysicsGeometry();
wall.setMaterial(Material.IRON);
//wall.computeMass();
n.attachChild(wall);
//n.setLocalScale(5);
rootNode.attachChild(n);
System.out.println("Test Class Added");
}
}
(Not the changes I made to your test, I would suggest copy/pasting this and running it yourself...)
Good to know, where the bug is hidding.
I'm using my own SimplePhysicsGame, therefore I will compare both of them with each other.
Thx
Found the problem, but I don't know why!?
Working:
input.update( tpf );
Not Working:
if (input != null) {
input.update(tpf);
}
Can someone explain this to me?
Hey…
The easiest/best way to get help (well IMO) is to whip up a test (generally use SimpleGame or SimplePhysicsGame) that can be run with little effort. This way it 1) helps whom-ever is helping you, 2) makes you take one more debugging step (the test should show the problem and nothing else), 3) creates a test case that can be easily changed and can validate both the problem and the solution.
You would be surprised how many times creating a test like that has helped me :).