Physcis to a ball

I’m trying to have a ball roll around in a simple square arena, however, none of the physics seems to be affecting the ball in any way. Holding down W has no effect, and since the ball starts in mid-air, I would expect it to fall; however, it does not. It just sits there floating.

public void simpleInitApp() {
    //Initialize Bullet
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    
    //Load simple arena
    Spatial m = assetManager.loadModel("Models/simple_arena/simple_arena.j3o");
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    m.setMaterial(mat);

    //Create a shape for the arena.
    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) m);
    landscape = new RigidBodyControl(sceneShape, 0);
    m.addControl(landscape);

    //Create a sphere for the ball.
    Sphere s = new Sphere(32, 32, .2f);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setTexture("ColorMap", assetManager.loadTexture("Textures/blue.png"));

    
    //Add a light for the texture.
    DirectionalLight sun = new DirectionalLight();
    sun.setColor(ColorRGBA.White);
    sun.setDirection(new Vector3f(-.5f, -.5f, -.5f).normalizeLocal());
    rootNode.addLight(sun);

    player = new Geometry("Player", s);
    player.setMaterial(mat2);

    player.setLocalTranslation(0, 2, 0);

    playerControl = new RigidBodyControl(new SphereCollisionShape(), 10f);
    player.addControl(playerControl);

    rootNode.attachChild(m);
    rootNode.attachChild(player);
    bulletAppState.getPhysicsSpace().add(landscape);
    bulletAppState.getPhysicsSpace().add(playerControl);
    bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, -9.8f, 0));

    initKeys();
}

private void initKeys() {
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addListener(actionListener, new String[]{"Up", "Left", "Right", "Down", "Jump"});
}
private AnalogListener actionListener = new AnalogListener() {
    public void onAnalog(String name, float value, float tpf) {
        if (name.equals("Left")) {
            playerControl.setPhysicsRotation(playerControl.getPhysicsRotation().fromAngleAxis(1, Vector3f.UNIT_Y));
        } else if (name.equals("Right")) {
            playerControl.setPhysicsRotation(playerControl.getPhysicsRotation().fromAngleAxis(-1, Vector3f.UNIT_Y));
        } else if (name.equals("Up")) {
            playerControl.setLinearVelocity(new Vector3f(1000,0,0));
        } else if (name.equals("Down")) {
        }
    }
};

I’m sure I’m missing a simple step, but I can’t see how many code is different from any of the examples in the tutorials.
Thanks

You using the default spherecollisionshape constructor, which is only there for serializing, try pass in a radius.

1 Like

That was it exactly, thank you very much.