Game Development Reference
In-Depth Information
Mathf.Abs(n)
is the function that will return the absolute number
n
.
For more details, visit the following websites:
6. Then, we need to create the
SetupRotation()
function to update the rotation
of our camera. Type in the following code:
// Unity JavaScript user:
function SetUpRotation ( centerPos : Vector3 ) {
var cameraPos : Vector3 =
_cameraTransform.position;
var offsetToCenter : Vector3 = centerPos -
cameraPos;
var yRotation : Quaternion =
Quaternion.LookRotation(new Vector3(offsetToCenter.x,
offsetToCenter.y + height, offsetToCenter.z));
var relativeOffset : Vector3 = Vector3.forward *
distance + Vector3.down * height;
_cameraTransform.rotation = yRotation *
Quaternion.LookRotation(relativeOffset);
}
// C# user:
void SetUpRotation ( Vector3 centerPos ) {
Vector3 cameraPos = _cameraTransform.position;
Vector3 offsetToCenter = centerPos - cameraPos;
Quaternion yRotation = Quaternion.LookRotation(new
Vector3(offsetToCenter.x, offsetToCenter.y + height,
offsetToCenter.z));
Vector3 relativeOffset = Vector3.forward * distance
+ Vector3.down * height;
_cameraTransform.rotation = yRotation *
Quaternion.LookRotation(relativeOffset);
}