0

I am trying my best to make an object fall, and so far I can't even come close. Here is the code i am trying.

    BulletAppState bulletAppState = new BulletAppState();

    cubemesh = new Box(1f,1f,1f);
    Geometry something = new Geometry("cube", cubemesh);
    Material bronze = new Material(assetManager, 
    "Common/MatDefs/Light/Lighting.j3md");
    something.setLocalTranslation(0,1,0);
    bronze.setTexture("DiffuseMap", assetManager.loadTexture("Textures/bronze.jpg"));
    something.setMaterial(bronze);
    rootNode.attachChild(something);

    RigidBodyControl control = new RigidBodyControl(10f);
    Vector3f direction = new Vector3f(0,-9.81f,0);
    something.addControl(control);

    //all the random lines i've tried
    stateManager.attach(bulletAppState);
    control.setGravity(direction);
    bulletAppState.getPhysicsSpace().setGravity(direction);
    rootNode.attachChild(something);
    bulletAppState.getPhysicsSpace().add(control);

Help will be appreciated.

user2999815
  • 101
  • 3
  • There are many examples in the jME wiki: http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_physics Anyway, did you attach `bulletAppState` to the `AppStateManager`? – 1000ml Dec 16 '15 at 04:10
  • Yes, i added in the line, forgot about it. – user2999815 Dec 16 '15 at 13:49
  • Can you see your object on the screen? Your code does not compile. It also doesn't include all the necessary stuff. Please read http://sscce.org and post a complete example that reproduces your problem. – 1000ml Dec 16 '15 at 14:41
  • done, just use a random jpg. (not in the mood for changing variable names) – user2999815 Dec 17 '15 at 17:25

1 Answers1

2

The physics in your example do work for me. But using your material, i can't see anything because there's no light.

Try attaching a Light:

AmbientLight light = new AmbientLight();
light.setColor(ColorRGBA.White);
rootNode.addLight(light);

Trying random lines won't get you very far. I recommend reading the jME wiki so you understand what these lines actually do. Here's a minimalistic example which uses a Material that doesn't need light:

public void simpleInitApp() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);

    Geometry something = new Geometry("cube", new Box(1,1,1));
    something.setMaterial( new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md") );
    something.setLocalTranslation(0,2,0);
    something.addControl( new RigidBodyControl(10f) );

    rootNode.attachChild(something);
    bulletAppState.getPhysicsSpace().add(something);
}

This example displays a colourful falling cube. If this doesn't work for you, there might be something wrong with your jME version or its setup (I'm using jMonkeyEngine 3.1-alpha1).

1000ml
  • 864
  • 6
  • 14