How to reset camera rotation/ position after "Free look"?
I've made a "free look" camera script for my car. It works - press and hold the button, and you can orbit your camera around; release it and it would jump to its initial position. The problem is - as I press and hold the button again, the camera jumps to the position where the button previously was released, but I need it to "not remember" that position and start from the initial position.. Can someone please help me? Here's the code:
void Update()
{
if (Input.GetKey(freeLookKey) && Time.timeScale > 0)
{
carController.enabled = false;
float mouseX = Input.GetAxis("Mouse X") * _mouseSensitivity;
float mouseY = -Input.GetAxis("Mouse Y") * _mouseSensitivity;
_rotationY += mouseX;
_rotationX += mouseY;
_rotationX = Mathf.Clamp(_rotationX, _rotationXMinMax.x, _rotationXMinMax.y);
Vector3 nextRotation = new Vector3(_rotationX, _rotationY);
_currentRotation = Vector3.SmoothDamp(_currentRotation, nextRotation, ref _smoothVelocity, _smoothTime);
transform.localEulerAngles = _currentRotation;
targetAngles.y = Mathf.Clamp(targetAngles.y, -rotationRange.y * 0.5f, rotationRange.y * 0.5f);
targetAngles.x = Mathf.Clamp(targetAngles.x, -rotationRange.y * 0.5f, rotationRange.x * 0.5f);
}
else
{
carController.enabled = true;
transform.localEulerAngles = new Vector3(0, 0, 0);
}
float fov = Camera.main.fieldOfView;
fov -= Input.GetAxis("Mouse ScrollWheel") * -sentivity;
fov = Mathf.Clamp(fov, minfov, maxfov);
Camera.main.fieldOfView = fov;
}
Your answer
Follow this Question
Related Questions
Creating a camera controller for isometric view - Positioning the camera 1 Answer
Transform.Rotate x and y rotate z, where z is 0 0 Answers
Rotate Camera in Y axis without visibly changing angle in Z axis 2 Answers
Maintaining Camera Rotation between modes 0 Answers
Make camera rotate around an object while keeping entire area visible 0 Answers