- Home /
Question by
Unitycode130 · Nov 21, 2016 at 10:10 PM ·
c#rotationquaternionsmoothslerp
Quaternion Rotation Smooth
I have this code that rotates my camera and it works great, but I would like to make the rotation movement to be smooth. How can I achieve this?
public float mouseSensitivity = 5.0f;
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
Comment
Answer by Namey5 · Nov 22, 2016 at 04:22 AM
public float speed = 3f;
public float mouseSensitivity = 5.0f;
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
Camera.main.transform.localRotation = Quaternion.Slerp (Camera.main.transform.localRotation, Quaternion.Euler(verticalRotation, 0, 0), Time.deltaTime * speed);
Just change the 'speed' variable as you need to control how quickly the rotation reaches its destination.
https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Quaternion.Slerp with Quaternion.LookRotation causes unexpected results 1 Answer
Choppy rotation of character around y-axis 1 Answer
i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers
few question about quaternion slerp 3 Answers