3
\$\begingroup\$

So I am trying to learn jMonkey, I have understood everything so far, and I thought I understood how to make objects solid, so things can't go through each other. When I create my Collision shapes, I turn on the debugger which shows the shapes, and they appear correct. But when I run the code the puck falls right through the table and I have no idea why? I have been trying to learn from http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_collision.

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();

        AppSettings settings = new AppSettings(true);
        settings.setResolution(1024,768);
        settings.setFrameRate(60);
        app.setSettings(settings);

        app.start();
    }

    private BulletAppState bulletAppState;

    private RigidBodyControl    table_phy;
    private RigidBodyControl    puck_phy;


    @Override
    public void simpleInitApp() {

        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        bulletAppState.getPhysicsSpace().enableDebug(assetManager);

        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
        rootNode.addLight(sun); 

        cam.setLocation(new Vector3f(0.0f, -2.0f, 7.0f));

        initTable();
        initPuck();
        initPusher1();
        initPusher2(); 

    }

  //My hockey table   
    public void initTable() {
        Spatial table = (Node)assetManager.loadModel("Models/airTable/airTable.j3o");
        table.setLocalTranslation(0.0f, -5.0f, -2.0f);
        CollisionShape tableShape = CollisionShapeFactory.createMeshShape((Node) table);
        table_phy = new RigidBodyControl(tableShape,0.0f);
        table.addControl(table_phy);
        rootNode.attachChild(table);
        bulletAppState.getPhysicsSpace().add(table_phy);
    }

    //My puck 
     public void initPuck(){
        Spatial puck = assetManager.loadModel("Models/puck/puck.j3o");
        puck.setLocalTranslation(1.0f, -3.0f, 0.0f);
        CollisionShape puckShape = CollisionShapeFactory.createMeshShape((Node) puck);
        puck_phy = new RigidBodyControl(puckShape, 0.05f);
        puck.addControl(puck_phy);
        rootNode.attachChild(puck);
        bulletAppState.getPhysicsSpace().add(puck_phy);
    }
}
\$\endgroup\$
1
\$\begingroup\$

From testing you code with my own models the only thing I can think of is your puck is clipping with the table on load.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.