Third Person Collision

Hi, I’m new in Jm3. I read and did beginner tutorials. Now Im trying to make a third person “game” and I have a problem. I have all graphics but I can’t detect collision. I want that Oto character can get inside figures. Here is my code. Any help will be appreciated.

public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();
bulletAppState.setDebugEnabled(true);

stateManager.attach(bulletAppState);
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);

// We re-use the flyby camera for rotation, while positioning is handled by physics
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
this.flyCam.setMoveSpeed(100);
this.setUpKeys();
this.setUpLight();
this.setUpAnimKeys();

// We load the scene from the zip file and adjust its size.
assetManager.registerLocator("town.zip", ZipLocator.class);
sceneModel = assetManager.loadModel("main.scene");
sceneModel.setLocalScale(2f);

// We set up collision detection for the scene by creating a
// compound collision shape and a static RigidBodyControl with mass zero.
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node)sceneModel);
landscape = new RigidBodyControl(sceneShape, 0f);
sceneModel.addControl(landscape);

// Set character
playerModel = (Node)assetManager.loadModel("Models/Oto/Oto.mesh.xml");
playerModel.setLocalTranslation(new Vector3f(0f,2f,0f));
playerModel.setLocalScale(0.4f);

// Set character collision shape

CollisionShape playerShape = CollisionShapeFactory.createMeshShape(playerModel);
//CapsuleCollisionShape playerShape = new CapsuleCollisionShape(1.5f, 6f, 1);
playerBodyControl = new CharacterControl(playerShape,0f);
playerModel.addControl(playerBodyControl);

//this is to try if user:pass works





//rootNode.attachChild(playerCharacter);
placeholder = new Node("Place Holder");

placeholder.attachChild(playerModel);

flyCam.setEnabled(false);
camNode = new CameraNode("Camera Node",cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
//camNode.attachChild(playerCharacter);

//playerCharacter.attachChild(camNode);
//rootNode.attachChild(camNode);
//camNode.attachChild(playerCharacter);

placeholder.attachChild(camNode);
camNode.setLocalTranslation(new Vector3f(0,12.5f,-12.5f));
rootNode.attachChild(placeholder);
//playerCharacter.setLocalTranslation(new Vector3f(0,-5,5));
camNode.lookAt(playerModel.getLocalTranslation(),Vector3f.UNIT_Y);

control = playerModel.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();  
channel.setAnim("stand");

//rootNode.attachChild(playerCharacter);

// We set up collision detection for the player by creating
// a capsule collision shape and a CharacterControl.
// The CharacterControl offers extra settings for
// size, stepheight, jumping, falling, and gravity.
// We also put the player in its starting position.

// CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
// player = new CharacterControl(capsuleShape, 0.05f);
// player.setJumpSpeed(20);
// player.setFallSpeed(30);
// player.setGravity(30);
// player.setPhysicsLocation(new Vector3f(0, 10, 0));

// We attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
rootNode.attachChild(sceneModel);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(playerBodyControl);

}

Sorry, I want Oto cannot get inside graphics

You need a class that implements the PhysicsCollisionListener interface, and then

bulletAppState.getPhysicsSpace().addCollisionListeneer(yourPhysicsCollisionListener);

Your listener will then be informed when there’s a collision between two shapes.

Thanks. Thats very good to know. Can I ask you where can I find a tutorial or something of that topic?

https://jmonkeyengine.github.io/wiki/jme3/advanced/physics_listeners.html#how-to-listen-to-collisions

Thanks Domenic