Game Development Reference
In-Depth Information
How to do it...
To start off, we can create a new SimpleApplication class in which we'll apply the
following steps:
1. To initialize the camera, you supply the application's camera, spatial , to be fol-
lowed, and the input manager, as follows:
ChaseCamera chaseCam = new ChaseCamera(cam,
playerNode, inputManager);
2. The ChaseCamera class has lots of settings to suit different kinds of games. To
start off, we turn off the need to hold down the left mouse button to rotate the cam-
era. It's not something we want for this recipe. This is implemented as follows:
chaseCam.setDragToRotate(false);
3. We do, however, want smooth movement for the camera. For this, type the follow-
ing line of code:
chaseCam.setSmoothMotion(true);
4. By default, the camera will focus on the origin point of spatial , which in this
case, would be Jaime's feet. We can easily make it look at a higher-up point, such
as waist.chaseCam.setLookAtOffset(new Vector3f(0, 1f,
0)); .
5. Next, we set some distance restrictions for the camera. There is no guarantee that it
will stay within those boundaries though. It especially seems to violate
minDistance :
chaseCam.setDefaultDistance(7f);
chaseCam.setMaxDistance(8f);
chaseCam.setMinDistance(6f);
6. The ChasingSensitivity method defines how quickly the camera will fol-
low spatial . If it's 1 , it will follow slowly and if it's 5 , it will follow quickly.
We want the camera to be pretty responsive in this recipe:
chaseCam.setChasingSensitivity(5);
Search WWH ::




Custom Search