[solved]space physics

Hello everyone,

I was trying jME 3 and tried using jBullet. I was trying to create a little simulation with two planets (spheres) , one orbiting the other. That did not work out, both of my planets were just… falling. Even with the Vector3f.ZERO gravity.

What am i doing wrong?


public void simpleInitApp() {

Material matyellow = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

matyellow.setColor("m_Color", ColorRGBA.Yellow);

Material matred = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

matred.setColor("m_Color", ColorRGBA.Red);

// Planet.Builder(name, mass, position, radius, material)

Planet sun = new Planet(new Planet.Builder("sun", 10f, Vector3f.ZERO, 10, matyellow));

Planet mercury = new Planet(new Planet.Builder("mercury", 1f, new Vector3f(0, 0, 25), 1, matred));

cam.setLocation(new Vector3f(0f, 0f, 50f));

cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

//now physics

bulletAppState = new BulletAppState();




bulletAppState.getPhysicsSpace().setWorldMin(new Vector3f(-30f, -30f, -30f));

bulletAppState.getPhysicsSpace().setWorldMax(new Vector3f(30f, 30f, 30f));

SphereCollisionShape sunCollisionShape= new SphereCollisionShape(10);

SphereCollisionShape mercuryCollisionShape= new SphereCollisionShape(1);

PhysicsNode sunNode = new PhysicsNode(sun, sunCollisionShape, sun.getMass());

PhysicsNode mercuryNode = new PhysicsNode(mercury, mercuryCollisionShape, mercury.getMass());







float xspeed = (float) Math.sqrt((double)(9.81f*sun.getMass()/250f));

mercuryNode.setLinearVelocity(new Vector3f(0, xspeed, 0));



When you add the object to the physicsspace the gravity of the physicsspace is applied to it, change either the gravity of the physicsspace before adding or the gravity of the planets after adding. I think this is mentioned in the javadoc, no?

well isn’t it what i did? the node are even created( l27 & 28) after the gravity is set (l20). And added to the rootnode on lines 30& 31!

Hm, well did you try setting the gravity to the planets directly?

yep! tried that too. no luck either.

You apply an upwards velocity to that object so it should move in that direction (Y) continuously because theres no gravity. What is happening now? Its moving upwards a bit and then falls down? If you could not set the gravity to zero by setting it directly then theres something else wrong in your code, that should definitely work.

well… both planets fall. Even if i only applied a velocity only to mercury, the ‘sun’ planet (sorry for that) falls as well. It goes well too fast for me to understand what happens to mercury, but it disappears very quickly at the beginning, and the sun falls slowly.

so jBullet does only compute the “global” gravity? there is no gravity forces between mercury and the sun in my program?

As said, no. Did you attachDebugShape() to see if they maybe overlap at the beginning?

ah sorry i misunderstood your last post.

i will try that tonight.

Ok found out how to do it. thanks for the information :slight_smile: it helped a lot. The sphere were overlapping, as i found out that moving the sphere does not move the collision sphere as well. so the collision sphere was in the middle of the second one…