Jmonkey:让RigidBodyControl对Gravity做出反应

时间:2015-12-15 16:00:24

标签: jmonkeyengine

我正尽力使物体掉落,到目前为止我甚至无法接近。这是我正在尝试的代码。

    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);

帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

你的例子中的物理学对我有用。但是使用你的材料,我看不到任何东西,因为没有光。

尝试附加Light

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

尝试随机行不会让你走得太远。我建议您阅读jME wiki,以便了解这些行的实际用途。这是一个简约的例子,它使用了一个不需要光的Material

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);
}

此示例显示彩色坠落立方体。如果这对您不起作用,则您的jME版本或其设置可能有问题 (我正在使用jMonkeyEngine 3.1-alpha1)。

相关问题