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));
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.