Changing gravity of an object

How would I change the gravity inside of a cube?

Change the gravity of the objects inside the cube.

Here is my code for one of the objects you dhow how to make the gravity of this sphere change ramdomly every 5 or so seconds?

Sphere sphere1 = new Sphere(32, 32, 0.25f);
Geometry ball1 = new Geometry(“Ball1”, sphere1);
Material sph1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material
sph1.setColor(“Color”, ColorRGBA.Yellow); // set color of material to yellow
ball1.setMaterial(sph1); // set the ball’s material
ball1.setLocalTranslation(2f, 5f, -2f); // Move it a bit
ball1.rotate(2f, 3f, 2f); // Rotate it a bit
RigidBodyControl ball_phy1 = new RigidBodyControl(1f); // Make the ball physcial with a mass > 0.0f
ball1.addControl(ball_phy1); // Add physical ball to physics space
bulletAppState.getPhysicsSpace().add(ball_phy1);
ball_phy1.applyCentralForce(new Vector3f(167f, 214f, 239f));
ball_phy1.setMass(1f);
ball_phy1.setKinematic(false);
rootNode.attachChild(ball1);

Not too hard:
[java]float timer = 0;
public void update(tpf){
timer++;
if(timer>5000){
obj.setGravity(new Vector3f(0,-randomizer.nextFloat()*10,0);
timer = 0;
}
}[/java]

1 Like

Thanks normen.