How to restrict a ball to roll only on the surface of some object like a cylinder?

Is there a way to set, take Cylinder as an example, the cylinder as the central of gravity? so the ball won’t fall away. Does anyone know? I have been recently working on a small game to get started with JME, but it seems objects affected by gravity only fall downward,.can I modify the gravity utility and set another object as the earth which grabs everything towards it.

I dont think you can have custom gravity directions. What you’ll probably have to do is write a custom control, say a FakeGravityControl. FakeGravityControl could have a centerOfGravity Vector3f property, which you set to the the center of your cylinder. Every update, you subtract a constant amount from the ball’s distance from the center and use that to update its location. Or something like that - there is probably a better Vector3f way of doing this.

Actually you can se thte direction of gravity, now just set the direction to point to the middle of the cylinder at each update. (Getting this to work nice will be a bit hack i assume tho.)

But wont that affect the entire physics space and not just the ball?

No, each rigidBody has its own method for setting gravity, read the javadoc on both the method on physicsSpace and RigidBody.

I checked the javadoc. there is no such functions. so I might do it as ancalagon suggested

@normen said:

No, each rigidBody has its own method for setting gravity, read the javadoc on both the method on physicsSpace and RigidBody.

http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/objects/PhysicsRigidBody.html#setGravity(com.jme3.math.Vector3f)

@shoulianyu said:
I checked the javadoc. there is no such functions. so I might do it as ancalagon suggested

When I tell you there is these methods then believe me, I wrote this wrapper xD