Moving Camera

Hi guys, How can i make the camera follow the mouse when it moves, up,down,left,right? My camera is attached to a spatial node, i want it to be locked above the Spatial, but have it moving up down,left,right.



Following code locks the Camera above the Spatial.

Code:
targetNode = (Node)rootNode.getChild("Engine_Camera_View");; // flyCam.setEnabled(false); camNode = new CameraNode("Camera Node",cam); camNode.setControlDir(ControlDirection.SpatialToCamera); targetNode.attachChild(camNode); //Move camNode, e.g. behind and above the target: camNode.setLocalTranslation(new Vector3f(15, 15, 0)); //Rotate the camNode to look at the target: camNode.lookAt(targetNode.getLocalTranslation(), Vector3f.UNIT_Y);

I had a look at Chase camera test, but that only moves when the user is dragging the spatial.

Easiest way would be to keep the flyCam on and then just move the cam to the spatial in the update loop, e.g. cam.setLocation(spatial.getWorldTranslation().add(new Vector3f(0,3,0));

But the user can still use w,a,d to move the cam around. Can i somehow override so that the fly cam does not move with w,a,s,d?

No he cannot if you do what I said. This is exemplified in HelloCollision btw.

The default cameras are designed as starting points/inspiration for making your own - not something that’s expected most people will use in a finished game.



Just take the code from flycam and keep the bits you want, remove the bits you don’t then in your SimpleApp constructor provide your new camera implementation app state instead of flycam.

Thanks Normen, it works :), @ Zarch i’m new to JME so just getting used to it :D.

@harmy said:
Thanks Normen, it works :), @ Zarch i'm new to JME so just getting used to it :D.

No worries, as first questions go it was a pretty sensible one :D

Just make sure you've done the tutorials. The scene graph/3d math ones are always essential and then for this topic the app states and camera ones.

also doing

flyCam.setMoveSpeed(0) will stop it moving via wasd, or you can disable the mappings maybe