Game Development Reference
In-Depth Information
2. Linearly interpolate from current facing to desired facing according to a
dampening factor.
3. Linearly interpolate from current height to desired height according to another
dampening factor.
4. Place the camera behind the track object, at the interpolated angle, facing
the track object so that the object of interest can be seen in view, as shown
in the following screenshot:
Now let's implement this algorithm in C# code by performing the following steps:
1. Right click on the
Chapter1 assets
folder and select
Create New C#
Script
. Name it
GameCam
and add it to the
Main Camera
object.
2. Create a public
GameObject
reference called
TrackObj
with the following
code. This will point to the
GameObject
that this camera is tracking at any
given time, as shown in the following code:
public GameObject trackObj;
3. Create the following four public float variables that will allow adjustment of
the camera behavior in the object inspector. We will leave these uninitialized