Question by
Will21 · Apr 10, 2017 at 03:47 PM ·
cameracamera rotateorientationcamera movementsmoothfollow
Change orientation of smooth follow camera?
At the moment, the smooth follow camera script follows my character. However, it looks at it from the left-hand side rather than from behind. How would I change the orientation from which the camera looks at it from? public Transform target; public float distance; public float height; public float heightDamping; public float rotationDamping;
void LateUpdate () {
if (!target) {
return;
}
float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3 (transform.position.x, currentHeight, transform.position.z);
transform.LookAt (target);
}
Comment