Hello,
My apologies if this is in the wrong spot… I am new to the forums and JME3!
So I am trying to make a node camera that follows the player (which is a lovely blue cube) as the player moves around the scene. I am using the basic town.zip scene from the tutorials, and am simply trying to add the cube and the camera-replacement as modifications of the HelloCollisions tutorial… however am having difficulty giving the cube physics.
Below is a section of the code, with comments to make it easier to read!:
Node playerNode = new Node("playerNode"); //creates player node
rootNode.attachChild(playerNode); //attaches player Node to the root Node
//Player Geometry
Box b = new Box(1, 1, 1); // create cube shape
Geometry playerGeo = new Geometry("Box", b); // create cube geometry from the shape
playerGeo.setLocalTranslation(new Vector3f(1,2,1)); //set cube location
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
playerGeo.setMaterial(mat); // set the cube's material
playerNode.attachChild(playerGeo); //attaches playerGeo to the player Node
//Player Physics
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
playerPhy = new CharacterControl(capsuleShape, 0.05f);
playerPhy.setJumpSpeed(20);
playerPhy.setFallSpeed(30);
playerPhy.setGravity(30);
playerPhy.setPhysicsLocation(new Vector3f(0, 10, 0));
//How do I attach playerPhy to playerNode?!?
// From tutorial: Attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
rootNode.attachChild(sceneModel); //attaches the scene
bulletAppState.getPhysicsSpace().add(landscape); //places physics on the landscape (scene)
bulletAppState.getPhysicsSpace().add(playerNode); //gives physics to the player node
How do I give the cube physics/be able to be controlled by the user?
Thank you in advance,
Sky