Problems with CameraNode

Here is the method that deal with the CameraNode:

[java] public void initCam() {

camNode = new CameraNode(“Camera Node”, cam);




chaseCam = new ChaseCamera(camNode.getCamera(), objeto, inputManager);




chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(mouseInput.BUTTON_LEFT),

new KeyTrigger(KeyInput.KEY_SPACE));

chaseCam.setMinVerticalRotation(-FastMath.PI / 2);





Ok, when I try to do anything with the camNode, like “camNode.move(0.1f,0f,0f)”, it just vanish, and together all is attached to this.

I am sure this is a principiant error, but I searched in wiki and forum all the day and only have found examples to jme2.

Any idea? :?

Well honestly this can’t work…

you create a cam node (which is attached to the camera), then you attach a chase cam to the cam and target the cam node…

This lead to a camera looking at itself with 2 controls that are getting in the way of each other.

Messy isn’t it?

What do you want to do exactly?

O.K. I quit:cry:. Have any way to make a spatial move together a chasecam?

Yeah, use CameraNode

One question:

If I use these line

[java] CameraNode camNode = new CameraNode("Camera Node", cam);


All I attach to camNode will move toghether te camera or not? :?

I dont know what the default is but you can configure both directions, cam->spatial and spatial->cam with setControlDir().

I think the problem is not in setControlDir (I tried the two directions).

A detail I notified is when I put this

[java] System.out.println(camNode.getLocalTranslation());[/java]

in simpleUpdate method it retrieves crazy numbers that continues changing when I do nothing with the camera :o.

Any more idea?

Another thing I discovered with

[java] public void simpleUpdate(float tpf) {

cube.setLocalTranslation(camNode.getLocalTranslation().x/10000, camNode.getLocalTranslation().y/10000, camNode.getLocalTranslation().z/10000);



is the camNode is moving to a infinitely distance behind of my cam, but it never move togheter the things that are attached to it.

I am each time more confuse about it.

If it was not clear at now, I just want a spatial that move following my cam.

The camNode uses a control, you need to configure it properly like this :


this means that when you move the node, the camera follows it.

The default behavior is the other way around.

When I put SpatialToCamera my cam just do not move for no one way, but in CameraToSpatial noting happens.

What should happen? The CameraNode moves with the camera… You have to attach something to see it and even then you will probably not see it because you look at it from inside.

The camNode definitly is not following the cam, I put this

[java] public void simpleUpdate(float tpf) {

//cube.setLocalTranslation(camNode.getLocalTranslation().x/10000, camNode.getLocalTranslation().y/10000, camNode.getLocalTranslation().z/10000);

System.out.println(cam.getLocation() + " " + camNode.getLocalTranslation());


and one part of results is that:

(3.730026, 1.4562137, 2.9943862) (6451.023, -34.56818, 1735.7721)

(3.7319357, 1.4578599, 2.991204) (6454.755, -33.11032, 1738.7633)

(3.733849, 1.459491, 2.9880195) (6458.489, -31.65083, 1741.7513)

(3.7357657, 1.4611071, 2.9848318) (6462.2246, -30.189722, 1744.7362)

(3.7376862, 1.4627088, 2.9816415) (6465.9624, -28.727013, 1747.7179)

(3.73961, 1.4642959, 2.9784484) (6469.702, -27.262716, 1750.6963)

(3.741538, 1.4658685, 2.9752526) (6473.444, -25.796848, 1753.6715)

(3.7434685, 1.4674269, 2.972053) (6477.1875, -24.329422, 1756.6436)

(3.7454035, 1.4689708, 2.9688516) (6480.933, -22.86045, 1759.6124)

(3.747341, 1.4705007, 2.965647) (6484.6807, -21.38995, 1762.5781)

(3.7492826, 1.4720167, 2.9624393) (6488.43, -19.917933, 1765.5405)

(3.7512274, 1.4735188, 2.9592285) (6492.1816, -18.444414, 1768.4998)

(3.7531755, 1.4750073, 2.9560153) (6495.935, -16.969406, 1771.4558)

(3.7551267, 1.476482, 2.9527998) (6499.69, -15.492924, 1774.4086)

(3.7570815, 1.4779432, 2.9495807) (6503.4473, -14.01498, 1777.3582)

(3.7590384, 1.4793909, 2.9463596) (6507.2065, -12.535589, 1780.3046)

(3.7609982, 1.4808251, 2.9431357) (6510.968, -11.054764, 1783.2477)

(3.762961, 1.4822462, 2.9399104) (6514.731, -9.572517, 1786.1876)

(3.7649257, 1.483654, 2.9366827) (6518.496, -8.088863, 1789.1243)

(3.7668927, 1.4850487, 2.933453) (6522.263, -6.6038146, 1792.0577)

(3.7688622, 1.4864302, 2.9302225) (6526.032, -5.1173844, 1794.9879)

(3.7708335, 1.4877987, 2.92699) (6529.803, -3.6295857, 1797.9149)

(3.7728062, 1.4891543, 2.9237566) (6533.576, -2.1404314, 1800.8386)

(3.7747805, 1.4904971, 2.9205227) (6537.351, -0.6499343, 1803.7592)

(3.7767565, 1.4918272, 2.917287) (6541.128, 0.84189296, 1806.6764)

(3.778734, 1.4931448, 2.9140503) (6544.9067, 2.3350377, 1809.5905)

(3.7807136, 1.4944499, 2.910812) (6548.6875, 3.8294876, 1812.5012)

(3.782694, 1.4957427, 2.9075725) (6552.47, 5.32523, 1815.4088)

(3.784677, 1.4970231, 2.9043317) (6556.255, 6.822253, 1818.3131)

(3.7866619, 1.4982916, 2.901089) (6560.0415, 8.320545, 1821.2142)

Please, have you any exemple of CameraNode working for jME 3?

I am start to think this only happen in my computer because I don’t find it in anywhere.

This is a working example of a camera moved by a node

You should see a cube with a monkey head getting away from the camera. In fact…it’s the camera that is getting away from the cube.

package mygame;


import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.CameraNode;

import com.jme3.scene.Geometry;

import com.jme3.scene.control.CameraControl.ControlDirection;

import com.jme3.scene.shape.Box;

import com.jme3.util.SkyFactory;


  • test
  • @author nehon


    public class Main extends SimpleApplication {

    public static void main(String[] args) {

    Main app = new Main();



    private CameraNode camNode;

    private Geometry geom;


    public void simpleInitApp() {

    //init scene

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

    mat.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));

    Box b = new Box(1, 1, 1);

    geom = new Geometry(“Box”, b);



    // load sky

    rootNode.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/”, false));

    ///////Camera Stuff///////

    //disabling the flyCam (more than one position control on the same cam = mess)


    //creating the node

    camNode=new CameraNode(“myCamera”,cam);

    //setting the control direction from node to camera (when you move the node, the camera follows)


    //attaching the node to the scene


    //Setting the node to look at the geom position in world space (this is passed to the camera)

    camNode.lookAt(geom.getWorldTranslation(), Vector3f.UNIT_Y);

    // setting the node position (this is passed to the camera since the control direction is spatial to camera)

    camNode.setLocalTranslation(5, 3, 5);



    public void simpleUpdate(float tpf) {

    //moving the node on each frame

    camNode.move(tpf, tpf, tpf);

    //re setting the look at attribute so the cam looks at the geom

    camNode.lookAt(geom.getWorldTranslation(), Vector3f.UNIT_Y);




So, thanks a lot nehon…

I just dont understood the reason of the CamerNode, what is the diference between attach something to it or rootNode if the things do not follow it? The reason of a node was not the things attached to it suffer the same movements?

Well, the camera is not a spatial and cannot be attached to the scene graph.

The purpose of the CameraNode is to be able to use the camera as any other node.

The first example I can think of is for cinematics. The cameraNode is used to handle camera switching, camera travelings etc (via motionTrack and cameraNode/cameraControls activations).

So, if what normen saied is wrong, have any way to make a spatial move together the camera (while the camera is under player control), using a ChaseCamera?

[edit] I discovered my error, I was trying to give two controllers to onde camera. -.-

And my up question persists…

Well now that you removed the two controllers, try enabling Cam to Spatial mode again.

trovolone said:
So, if what normen saied is wrong

That never append! you must have misunderstood :p

You should tell us want you want to do, instead of what you are trying to do, maybe we'll be able to help more efficiently then.