Game Development Reference
In-Depth Information
Developing the camera code
In our 3D game, the main camera mode will follow a third-person algorithm. This
means that it will follow the player from behind, trying to keep the player on screen
and centered in view at all times. Before we start developing the camera, we need
to think about the basic requirements of our game in order to be able to program the
camera to achieve good cinematographic results. This list of requirements will grow
over time; however, by considering the requirements early on, we build an extens-
ible system throughout the course of this topic by applying good system design in our
software. In no particular order, we list the requirements of a good camera system as
follows:
• It needs to be able to track the hero at a pleasing distance and speed and in
an organic way
• It needs to be able to transition in an appealing way, from tracking various ob-
jects
• It needs to be able to frame objects in the field of view, in a cinematic and
pleasing way
Starting with an initial camera and motion system based on the Unity3D examples,
we will extend these over time. We do this not only because it is instructive but also
with the aim of extending them and making them our own over time. With these re-
quirements in mind, let's build the camera code. Before we do, let's consider some
pseudocode for the algorithm.
Implementing GameCam.cs
The GameCam script is the class that we will attach our MainCamera object to; it will
be responsible for the motion of our in-game camera and for tracking the player on
screen. The following five steps describe our GameCam camera algorithm:
1. For every frame that our camera updates, if we have a valid trackObj
GameObject reference, do the following:
1. Cache the facing angle and the height of the object we are tracking.
2. Cache the current facing angle and height of the camera (the
GameObject that this script is attached to).
Search WWH ::




Custom Search