I am trying to show the collision shape using the below code, yet it doesn’t show. What am I doing wrong?
[java]
public void createPlayer(AssetManager assetManager, Node rootNode){
playerSpatial= assetManager.loadModel(“Models/Box001/Box001.j3o”);
Box playerB = new Box(new Vector3f(0,0,0), 1, 1, 1);
playerGeom = new Geometry(“Player”, playerB);
playerGeom.setMaterial(assetManager.loadMaterial(“Materials/Player.j3m”));
playerGeom.setLocalTranslation(0, 0, 10);
playerSpatial.setLocalTranslation(0, 0, 10);
rootNode.attachChild(playerGeom);
rootNode.attachChild(playerSpatial);
}
public void physics(BulletAppState bulletAppState, AssetManager assetManager){
SphereCollisionShape capsuleShape = new SphereCollisionShape(1f);
player = new CharacterControl(capsuleShape, 0.1f);
player.setPhysicsLocation(new Vector3f(0, 0, 0));
bulletAppState.getPhysicsSpace().add(player);
CollisionShape sceneShapeG = CollisionShapeFactory.createMeshShape(playerSpatial);
rigidBodyControl = new RigidBodyControl(sceneShapeG, 0);
playerSpatial.addControl(rigidBodyControl);
bulletAppState.getPhysicsSpace().add(player);
player.setGravity(0);
player.setFallSpeed(0);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
}
[/java]
You are somehow confused in that code… You create two physics controls, one character and one rigid body. You first create a “player” CharacterControl with a sphere collision shape that you later do not attach to any spatial (this is why you don’t see it - it has no visual representation). Then you create MeshCollisionShape off the Geometry of the player spatial and make a static RigidBody (mass=0) from it that you also attach to the player spatial. So all you should see is a static blue box. The character, since its added to the physics space will probably bounce off it but since its got no visual representation you don’t see that.
[java]
bulletAppState.getPhysicsSpace().add(player);//this line is duplicated
CollisionShape sceneShapeG = CollisionShapeFactory.createMeshShape(playerSpatial);
rigidBodyControl = new RigidBodyControl(sceneShapeG, 0);
playerSpatial.addControl(rigidBodyControl);
bulletAppState.getPhysicsSpace().add(player);//copy paste error (same as above!), should be
bulletAppState.getPhysicsSpace().add(rigidBodyControl);
[/java]
I’m not sure, if that solves your problem…