When trying to make objects floating in space, the objects still slow down and stop. Is there something I have missed?
As as simple example I added this to the standard new project:
[java]
stateManager.attach(new BulletAppState());
stateManager.getState(BulletAppState.class).getPhysicsSpace().setGravity(Vector3f.ZERO);
geom.addControl(new RigidBodyControl(1f));
geom.getControl(RigidBodyControl.class).setDamping(0f, 0f);
geom.getControl(RigidBodyControl.class).setFriction(0f);
geom.getControl(RigidBodyControl.class).applyCentralForce(Vector3f.UNIT_Y);
stateManager.getState(BulletAppState.class).getPhysicsSpace().add(geom);
[/java]
Full example:
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
stateManager.attach(new BulletAppState());
stateManager.getState(BulletAppState.class).getPhysicsSpace().setGravity(Vector3f.ZERO);
geom.addControl(new RigidBodyControl(1f));
geom.getControl(RigidBodyControl.class).setDamping(0f, 0f);
geom.getControl(RigidBodyControl.class).setFriction(0f);
geom.getControl(RigidBodyControl.class).applyCentralForce(Vector3f.UNIT_Y);
stateManager.getState(BulletAppState.class).getPhysicsSpace().add(geom);
}
}
[/java]
It seems it only happens when the velocity is below a certain magnitude. Any idea why?
Don’t know but maybe setSleepingThreshold is what you need, described here:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics
Ah, thanks for that. The default for linear movement seems to be 0.8. Setting it to zero makes things move as they should.