Game Development Reference
In-Depth Information
v3_centerOffset = characterController.bounds.center - target.
position;
}
In this funcion, we get the camera transform and the CharacterController
script to get the center posiion of the target, which is the character we are
poining at.
3. Then, we will create a funcion to get the angle distance between the current angle
and target; let's add the following code:
//Get the angle distance between two angle
//This function took from the built-in Third-person Camera Script
public function AngleDistance (a : float, b : float) : float {
//Loop the value a and b not higher than 360 and not lower than
0
a = Mathf.Repeat(a, 360);
b = Mathf.Repeat(b, 360);
return Mathf.Abs(b - a);
}
4. Next, we will create the LateUpdate() funcion to update the camera posiion and
rotaion ater all the objects have their Update funcions called. So, let's add the
following code.
The LateUpdate() funcion is the funcion that will be called ater the
Update() funcion has been called. This funcion will make sure that all
the calculaion in the Update() funcion is inished before we start the
LateUpdate() funcion. We can see more details of this funcion at the
following Unity website:
http://unity3d.com/support/documentation/
ScriptReference/MonoBehaviour.LateUpdate.html .
//We use LateUpdate here because we need to wait for the user
input before we update our camera.
public function LateUpdate () : void {
var v3_targetCenter : Vector3 = target.position + v3_
centerOffset;
//Calculate the current & target rotation angles
var f_originalTargetAngle : float = target.eulerAngles.y;
var f_currentAngle : float = cameraTransform.eulerAngles.y;
var f_targetAngle : float = f_originalTargetAngle;
 
Search WWH ::




Custom Search