# Can you smooth the Rotate method?

I have a working camera system for a space sim but would like to smooth the camera. There a way to use SmoothDamp with this code?

``````void UpdateRotation()
{
if (transform.localRotation.x < -90 || transform.localRotation.x > 90)
yaw = -Input.GetAxis ("Mouse X") * mouseSensitivity;
else
yaw = Input.GetAxis ("Mouse X") * mouseSensitivity;

pitch = -Input.GetAxis ("Mouse Y") * mouseSensitivity;
roll = Input.GetAxis ("Roll") * rollSpeed;

transform.Rotate (pitch, yaw, roll, Space.Self);
}
``````

I found a way to smooth the camera movement, for any interested, but now when the cameras horizontal input is reversed when its X rotation is below -90 or above 90 degrees. Line 3 should be fixing this right?

``````void UpdateRotation()
{
if (transform.localRotation.x < -90 || transform.localRotation.x > 90)
yaw -= Input.GetAxis ("Mouse X") * mouseSensitivity;
else
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity;

pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
roll += Input.GetAxis ("Roll") * rollSpeed;

currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw, roll), ref velocity, smoothTime);
transform.eulerAngles = currentRotation;
}
``````

localRotation is a Quaternion so x (as in x,y,z,w: Quaternion coordinates) is not the same as Euler angles (x,y,z). unless youâ€™re a mathmatician and know Quaternions inside and out, use the Euler angles.

``````        float sign = (transform.localEulerAngles.x >= -90 && transform.localEulerAngles.x <= 90)? 1:-1;
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity * sign;
``````

I actually found another way, but thank you.

``````void UpdateRotation()
{
yaw = Input.GetAxis ("Mouse X") * mouseSensitivity;
pitch = -Input.GetAxis ("Mouse Y") * mouseSensitivity;
roll = Input.GetAxis ("Roll") * rollSpeed;

targetRotation = new Vector3 (pitch, yaw, roll);
currentRotation = Vector3.SmoothDamp (currentRotation, targetRotation, ref velocity, smoothTime);

transform.Rotate (currentRotation, Space.Self);
}
``````