camNode not colliding with a geometry called itembox1

I made a camNode which has a character control attached to it with a capsule collision shape. i am trying to get it to collide with a box shaped geometry called itembox1 with a rigidbodycontrol that has a mass of zero and is attached to itembox1. when i use camNode.collideWith(itembox1,res); the camNode never collides with the itembox1 and if i use a geometry such as another box with collideWith, the code has an error.

pre type="java"
package megaman;





import com.jme3.app.SimpleApplication;


import com.jme3.audio.AudioNode;


import com.jme3.collision.Collidable;


import com.jme3.math.Vector3f;


import com.jme3.bullet.BulletAppState;


import com.jme3.bullet.control.RigidBodyControl;


import com.jme3.bullet.collision.shapes.;


import com.jme3.bullet.util.CollisionShapeFactory;


import com.jme3.scene.Node;


import com.jme3.bullet.control.CharacterControl;


import com.jme3.bullet.control.GhostControl;


import com.jme3.collision.CollisionResults;


import com.jme3.effect.ParticleEmitter;


import com.jme3.effect.ParticleMesh;


import com.jme3.font.BitmapText;


import com.jme3.input.KeyInput;


import com.jme3.input.controls.ActionListener;


import com.jme3.input.controls.KeyTrigger;


import com.jme3.input.controls.MouseButtonTrigger;


import com.jme3.light.AmbientLight;


import com.jme3.material.Material;


import com.jme3.material.RenderState.BlendMode;


import com.jme3.math.ColorRGBA;


import com.jme3.math.FastMath;


import com.jme3.math.Matrix3f;


import com.jme3.math.Matrix4f;


import com.jme3.math.Quaternion;


import com.jme3.math.Ray;


import com.jme3.math.Vector2f;


import com.jme3.renderer.Camera.FrustumIntersect;


import com.jme3.renderer.queue.RenderQueue.Bucket;


import com.jme3.scene.Geometry;


import com.jme3.scene.Mesh;


import com.jme3.scene.Spatial;


import com.jme3.scene.shape.Box;


import com.jme3.scene.shape.Quad;


import com.jme3.scene.shape.Sphere;


import com.jme3.system.AppSettings;


import com.jme3.texture.Texture;


import com.jme3.ui.Picture;


import com.jme3.ui.Picture;


import com.jme3.util.SkyFactory;





public class rpgGame extends SimpleApplication implements ActionListener {





    boolean left, right, up, down, _RELOAD, shoot, crouch, nextWep, imReloading = false, sendGunUp = false, goright = true, goleft = false, goup = true, godown = false, cantStrafe = false;


    CharacterControl player;


    RigidBodyControl landscape;


    BulletAppState bulletAppState;


    Vector3f walkDirection = new Vector3f();


    AudioNode shootSFX, reloadSFX;


    ParticleEmitter spark;


    int updateDelay = 0, mysboxframe = 1;


    Node camNode;


    float m16_x, m16_y, m16_z, recx = 0, recy = 0, recoil_z = 0;


    AmbientLight light;


    CapsuleCollisionShape capsule1;


    Geometry itembox1;


    Material mysteryboxm;


    Vector3f boxcollide1;


    RigidBodyControl itemc;


    Box charbox = new Box(Vector3f.ZERO, 5, 5, 5);


    Geometry charc;





    public static void main(String[] args) {


        rpgGame app = new rpgGame(); //Create a class object and start the app


        AppSettings settings = new AppSettings(true);


        settings.setFrameRate(60);


        settings.setHeight(600);


        settings.setWidth(800);


        app.setSettings(settings);


        app.start(); //Start the app to play the game


    }





    @Override


    public void simpleInitApp() {


        charc = new Geometry(“Character”, charbox);


        loadKeys();


        viewPort.setBackgroundColor(ColorRGBA.Cyan);


        bulletAppState = new BulletAppState(); //Create the physics object


        stateManager.attach(bulletAppState); //Attach the physics object to the game


        bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0f, -1f, 0f));


        light = new AmbientLight();


        light.setColor(ColorRGBA.White);


        rootNode.addLight(light);





        camNode = new Node(“Camera Node”);





        Box box = new Box(Vector3f.ZERO, 4, 4, 4);


        Material floorTile = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);


        floorTile.setTexture(“ColorMap”, assetManager.loadTexture(“rpg/tile1.png”));


        Material brickTile = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);


        brickTile.setTexture(“ColorMap”, assetManager.loadTexture(“rpg/tile2.png”));


        mysteryboxm = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);


        mysteryboxm.setTexture(“ColorMap”, assetManager.loadTexture(“rpg/item1.png”));





        Geometry floorTiles[] = new Geometry[300];


        for (int a = 0; a < floorTiles.length; a++) {


            floorTiles[a] = new Geometry("Floor Tile " + a, box);


            floorTiles[a].setMaterial(floorTile);


            floorTiles[a].move(0, -4, a 
 8);


            rootNode.attachChild(floorTiles[a]);


            RigidBodyControl tilec = new RigidBodyControl(0);


            floorTiles[a].addControl(tilec);


            bulletAppState.getPhysicsSpace().add(tilec);


        }





        itembox1 = new Geometry(“Item Box With Mushroom”, box); //This box appears above the 17th floor tile


        itembox1.setMaterial(mysteryboxm);


        itembox1.move(0, 5, floorTiles[16].getLocalTranslation().z);


        rootNode.attachChild(itembox1);


        itemc = new RigidBodyControl(50);


        itembox1.addControl(itemc);


        bulletAppState.getPhysicsSpace().add(itemc);


        itemc.setGravity(Vector3f.ZERO);





        capsule1 = new CapsuleCollisionShape(5, 5, 1);


        player = new CharacterControl(capsule1, 0.05f); //0.05f default for step size


        player.setJumpSpeed(20);


        player.setFallSpeed(30);


        player.setGravity(30);


        player.setPhysicsLocation(new Vector3f(0, 5, 0));


        bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0f, -1f, 0f));


        bulletAppState.getPhysicsSpace().add(player);


 


    }


    CollisionResults res = new CollisionResults();





    @Override


    public void simpleUpdate(float tpf) {


        Vector3f camDirection = cam.getDirection().clone().multLocal(0.4f); //0.6f


        Vector3f camLeft = cam.getLeft().clone().multLocal(0.2f);


        camDirection.y = 0;


        camLeft.y = 0;


        walkDirection.set(0, 0, 0);


        if (left) {


            walkDirection.addLocal(camLeft);


        }





        if (right) {


            walkDirection.addLocal(camLeft.negate());


        }


        if (up) {


            walkDirection.addLocal(camDirection);


        }


        if (down) {


            walkDirection.addLocal(camDirection.negate());


        }


        player.setWalkDirection(walkDirection);


        cam.setLocation(player.getPhysicsLocation());


        camNode.setLocalRotation(cam.getRotation());


        camNode.setLocalTranslation(cam.getLocation());





        camNode.collideWith(itembox1,res);


        System.out.println(res);


    }





    public void loadKeys() {


        inputManager.addMapping(“Left”, new KeyTrigger(KeyInput.KEY_A));


        inputManager.addMapping(“Right”, new KeyTrigger(KeyInput.KEY_D));


        inputManager.addMapping(“Up”, new KeyTrigger(KeyInput.KEY_W));


        inputManager.addMapping((“Down”), new KeyTrigger(KeyInput.KEY_S));


        inputManager.addMapping(“Jump”, new KeyTrigger(KeyInput.KEY_SPACE));


        inputManager.addListener(this, “Left”);


        inputManager.addListener(this, “Right”);


        inputManager.addListener(this, “Up”);


        inputManager.addListener(this, “Down”);


        inputManager.addListener(this, “Jump”);


        inputManager.deleteMapping(“FLYCAM_ZoomIn”);


        inputManager.deleteMapping(“FLYCAM_ZoomOut”);


    }





    public void onAction(String binding, boolean value, float tpf) {


        if (binding.equals(“Left”)) {


            if (value) {


                left = true;


            } else {


                left = false;


            }


        } else if (binding.equals(“Right”)) {


            if (value) {


                right = true;


            } else {


                right = false;


            }


        } else if (binding.equals(“Up”)) {


            if (value) {


                up = true;


            } else {


                up = false;


            }


        } else if (binding.equals(“Down”)) {


            if (value) {


                down = true;


            } else {


                down = false;


            }


        } else if (binding.equals(“Jump”)) {


            player.jump();


        }


    }


}



/pre

For physics objects collision checking implement PhysicsCollisionListener and register it on PhysicsSpace instead. Just use CollisionResults for non-physics objects.

im having a bit of trouble understanding the tutorial on physics listeners.Do i have to make another class just for a physics control? Im really confused.

No, just implement a PhysicsCollisionListener and register it on PhysicsSpace. You can create yourself PhysicsCollisionListenerImpl class that implements the PhysicsCollisionListener, and register it on PhysicsSpace by:

[java]

physicsSpace.addCollisionListener(new MyPhysicsCollisionListenerImpl());

[/java]



Edit: At “collision()” overriden method you can check the collisions between your physics objects.

so in the other class, i would have the collision() method or what else would it exactly have in it?





EDIT: I got it to work, thanks for the help! :smiley: