Rigid bodies moving by themselves

Hello everybody,
First of all, apologies for my english, I’m italian :slight_smile:
I’m learning how to use jMonkeyEngine and I tried to modify the HelloPhysic expample: I put a box (rigid body) on a floor (static body), but when the program is running, the box moves by itself. It’s hard to explain, so I uploaded a video, so you can see the problem.

video

How can I fix this thing?

Thanks everybody.

Thats inaccurate math, you can try to higher the friction of the box/floor to prevent sliding.
Also you can set sleepthresholds so, that the box starts to sleep when its more or less standing still.

i think that something alive is in that box :smiley:

Neither solution worked. Any other tips?

Can you show us the code where you create the box and the ground? (Or if its in a more complex case create a simple testcase out of it, that represents the problem)

I created a test case with the same problems. I omitted all the imports…
[java]

// imports

public class Test extends SimpleApplication {
public static void main(String args[]){
Test app=new Test();
app.start();
}

private BulletAppState bulletAppState;
Material boxMat;
Material groundMat;

private RigidBodyControl box_phy;
private static final Box box;
private RigidBodyControl ground_phy;
private static final Box ground;

static{
    box=new Box(0.088f,0.055f,0.024f);
    ground=new Box(1.09f,0.015f,0.21f);
}

@Override
public void simpleInitApp(){
    bulletAppState=new BulletAppState();
    stateManager.attach(bulletAppState);    
    cam.setLocation(new Vector3f(3f,1.8f,2.3f));
    cam.lookAt(new Vector3f(1,0.3f,0),Vector3f.UNIT_Y);
    
    initMaterials();
    initGround();
    initBox();
    
}

public void initMaterials(){
    boxMat=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
    boxMat.setColor("Color", ColorRGBA.Blue);
    
    groundMat=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
    groundMat.setColor("Color",ColorRGBA.Red);
}

public void initGround(){
    Geometry ground_geo=new Geometry("Ground",ground);
    ground_geo.setMaterial(groundMat);
    ground_geo.setLocalTranslation(0,-0.093f,0);
    this.rootNode.attachChild(ground_geo);
    ground_phy=new RigidBodyControl(0);
    ground_geo.addControl(ground_phy);
    ground_phy.setFriction(1f);
    bulletAppState.getPhysicsSpace().add(ground_phy);
}

public void initBox(){
    Geometry box_geo=new Geometry("Box",box);
    box_geo.setMaterial(boxMat);
    box_geo.setLocalTranslation(1.04f,0.001f,0.03f);
    this.rootNode.attachChild(box_geo);
    box_phy=new RigidBodyControl(2f);
    box_geo.addControl(box_phy);
    box_phy.setFriction(1f);
    bulletAppState.getPhysicsSpace().add(box_phy);
}

}
[/java]

Hm your box is too smal, try using a larger one for a test, bullet does not work well with very small and very large objects.
http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Scaling_The_World

1 Like

Nothing at all, even if I create a box 1x1x1 large, it moves itself!

Scaling by 10 works fine

[java]package com.mmm.util.test;

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.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.tools.Color;

public class TestMovingBox extends SimpleApplication {

public static void main(String args[]) {
    TestMovingBox app = new TestMovingBox();
    app.start();
}
private BulletAppState bulletAppState;
private Material boxMat;
private Material groundMat;
private RigidBodyControl box_phy;
private static final Box box;
private RigidBodyControl ground_phy;
private static final Box ground;

static {
    box = new Box(0.88f, 0.55f, 0.24f);
    ground = new Box(11.90f, 0.15f, 2.1f);
}

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    cam.setLocation(new Vector3f(3f, 3.8f, 10.3f));
    cam.lookAt(new Vector3f(7, 0.3f, 0), Vector3f.UNIT_Y);

    initMaterials();
    initGround();
    initBox();

}

public void initMaterials() {
    boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    boxMat.setColor("Color", ColorRGBA.Blue);

    groundMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    groundMat.setColor("Color", ColorRGBA.Red);
}

public void initGround() {
    Geometry ground_geo = new Geometry("Ground", ground);
    ground_geo.setMaterial(groundMat);
    ground_geo.setLocalTranslation(0, -0.093f, 0);
    this.rootNode.attachChild(ground_geo);
    ground_phy = new RigidBodyControl(0);
    ground_geo.addControl(ground_phy);
    ground_phy.setFriction(1f);
    bulletAppState.getPhysicsSpace().add(ground_phy);
}

public void initBox() {
    Geometry box_geo = new Geometry("Box", box);
    box_geo.setMaterial(boxMat);
    box_geo.setLocalTranslation(11.35f, 0.6f, 0.03f);
    this.rootNode.attachChild(box_geo);
    box_phy = new RigidBodyControl(2f);
    box_geo.addControl(box_phy);
    box_phy.setFriction(1f);
    bulletAppState.getPhysicsSpace().add(box_phy);
}

}
[/java]

Ok, my mistake.
By the way, it seems not working if I apply textures to objects…

what doesn’t work?

I mean, the original problem (rigid bodies moving by themselves) seems to happen if I put a texture on a rigid body.

they aren’t connected at all though. Out of curiosity I tried it anyways, and yep still works

Yes, it works. Just tested a little bit more.

Thank you!!!