Game Development Reference
In-Depth Information
and then find working default values with the inspector, as shown in the fol-
lowing code:
Public float height;
Public float desiredDistance;
Public float heightDamp;
Public float rotDamp;
4. Recall that the Update() loop of any GameObject gets called repeatedly
while the game simulation is running, which makes this method a great can-
didate in which we can put our main camera logic. Hence, inside the Up-
date() loop of this script, we will call a UpdateRotAndTrans() custom
method, which will contain the actual camera logic. We will place this logic
inside the UpdateRotAndTrans() method. This method will update the ro-
tation (facing angle) and translation (position) of the camera in the world; this
is how GameCam will accomplish the stated goal of moving in the world and
tracking the player:
void Update() {
UpdateRotAndTrans();
}
5. Above the update loop, let's implement the UpdateRotAndTrans() meth-
od as follows:
void UpdateRotAndTrans () {
// to be filled in
}
6. Inside this method, step 1 of our algorithm is accomplished with a sanity
check on trackObj . By checking for null and reporting an error to de-
Search WWH ::




Custom Search