Making my table solid doesn't seem to work

So I have the object “puck” and I’m using it to test the table, which should be solid. As it will be part of my Air hockey game of course. But it passes right on through? I’m struggling to understand how to properly apply the collision shapes and then the physics for it? I’ve tried going through the wiki’s and the basic beginner book but I seem to get nowhere. Do I have to turn the spatials into geometries first? I’m really sorry for newby questions. Been trying to fix it for a while a now.

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.Spatial;
import com.jme3.light.DirectionalLight;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector2f;
import com.jme3.input.controls.*;
import com.jme3.input.*;
import com.jme3.app.Application;
import com.jme3.renderer.Camera;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.scene.Node;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
 

/**
 * test
 * @author mentosss
 */
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 Spatial pusher2;
    private Spatial table;
    private RigidBodyControl    table_phy;
    private RigidBodyControl    puck_phy;
    private RigidBodyControl    pusher1_phy;
    private RigidBodyControl    pusher2_phy;
    
    Boolean isRunning=true;
    
        
    
    @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, 3.0f, 7.0f));
        
        inputManager.addMapping("Forward", new KeyTrigger(KeyInput.KEY_W));
        inputManager.addMapping("Backward", new KeyTrigger(KeyInput.KEY_S));
        inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
        inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
        inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));
        
        inputManager.addListener(actionListener,"Pause");
        inputManager.addListener(analogListener,"Left", "Right", "Forward", "Backward");
        
        
        initTable();
        initPuck();
        initPusher1();
        initPusher2(); 
        
        
                             
    }
    
    
    public void initTable() {
        table = assetManager.loadModel("Models/airTable/airTable.j3o");  
        table.setLocalTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
        CollisionShape tableShape = CollisionShapeFactory.createMeshShape((Node) table);
        table_phy = new RigidBodyControl(tableShape,0.0f);
        table_phy.setPhysicsLocation(new Vector3f(0.0f, 0.0f, 0.0f));
        table.addControl(table_phy);
        bulletAppState.getPhysicsSpace().add(table_phy);
        rootNode.attachChild(table);
    }
                          
    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_phy.setPhysicsLocation(new Vector3f(0.0f, -3.0f, 0.0f));
        puck.addControl(puck_phy);
        rootNode.attachChild(puck);
        bulletAppState.getPhysicsSpace().add(puck_phy);
    }

Moving objects can’t be mesh shapes.

Would that be the only problem? Change the type of shape for the puck?

Well what happens if you do that?

I created a capsule shape and it did work, but its a bad shape for a puck. I tried getting the Cylinder shape to work, but couldnt, it seems quite complicated to use?

Not really if you read the javadoc and maybe use the debug display to see what you do.

From looking at coding examples, people seem to create new methods for it? use halfExtents?

New methods? I don’t know what you mean by that.

Here, look at the third constructor:
http://javadoc.jmonkeyengine.org/com/jme3/bullet/collision/shapes/CylinderCollisionShape.html

Nvm, looking at another example confused me. I also forgot to use the import >< Me being stupid. Thank you for the help.
How do I get it to go around the object then? As at the moment it seems to attach on an invisible corner?
I’m using:

CylinderCollisionShape puckShape = new CylinderCollisionShape(new Vector3f(0.1f, 0.1f, 0.1f));

The “invisible corner” is the center of your puck object. Either move the puck to the center in your 3d editor or attach it to a node to move it.

Thank you! much easier to change in the editor :slight_smile: