[Fixed] Node Camera Help


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.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,


You should go through all of the tutorials and not just pick and choose. Then you will learn about controls and stuff… and if you made it far enough you’d have found:

1 Like

And more generally, if you are ever in a situation where you are asking yourself “I wonder how I do X with Y?” (As in “I wonder how I add a Control to a Node?”)

Your very single most ultimate first reaction should be “I wonder what the javadoc for Y says?” And if not found there, “Gee, looks like Y extends Z… I wonder what the javadoc for Z says?”

90% of all answers to such questions will be found this way and you can look super-smart.

1 Like

My apologies, I had in fact overlooked that section… Thank you, and I’ll be sure to complete all the tutorials before asking another question!