Game Development Reference
In-Depth Information
Vector3f camLocation2D =
camLocation.add(camDirOffset).multLocal(UNIT_XZ);
8. We're using a linear interpolation that moves the camera's focus point 30 percent
closer to the target location each cycle. Then, we reverse the addition we did
earlier (or unproject) to get a new 3D position for the camera. The distance check
is optional, but since we're going to use interpolation, we might save a few calcu-
lations by only interpolating if the distance is above a certain threshold as fol-
lows:
if(targetLocation2D.distance(camLocation2D) > 0.01f){
camLocation2D.interpolate(targetLocation2D, 0.3f);
camLocation.set(camLocation2D);
camLocation.subtractLocal(camDirOffset);
9. To show that these changes work, we need to change a few things in our test ap-
plication. We can grab Jaime from our scene and use his translation as the target
location. We use worldTranslation and not localTranslation in this
case:
appState.setTargetLocation(jaime.getWorldTranslation());
appState.setFollow(true);
10. Then, in the update method of the test case, we make him slowly move along
the x axis as follows:
jaime.move(0.2f * tpf, 0, 0);
11. While running the application, we should see the camera follow Jaime until we
move it manually.
Search WWH ::




Custom Search