- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Yoshimiii · Oct 21, 2014 at 07:04 PM ·
rotate-around
Smoothfollow script C# How to rotate the camera?
I'm using C# version of unity sample script of SmoothFollow. I want to rotate the camera to multiple different positions. I have only been able to rotate around the X axis so far by modifying `float wantedRotationAngle = target.eulerAngles.y;` to `float wantedRotationAngle = target.eulerAngles.y + 90;` Thanks.
void LateUpdate ()
{
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
//rotate camera
transform.position -= currentRotation * (new Vector3 (0, 0, 1)) * distance;
// Set the height of the camera
transform.position = new Vector3 (transform.position.x, currentHeight, transform.position.z);
// Always look at the target
transform.LookAt (target);
}
Comment
Your answer
Follow this Question
Related Questions
Rotate the object using device acceleration 1 Answer
transform.RotateAround in a specific amount of time? 1 Answer
Make object rotate about a circle with fixed velocity after collision 0 Answers
How can I make a object/sprite rotate around another object/sprite using rigidbody 0 Answers
How do I rotate my Camera around my sphere using the arrow keys? 0 Answers