- Home /
Aligning/mapping angles of Input.GetAxis(with .localEulerAngles
I have a customized smoothed mouselook script based on this script. The update function begins like this:
rotAverageY = 0f;
rotAverageX = 0f;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY = ClampAngle( rotationY, minimumY, maximumY );
//rotationX = ClampAngle( rotationX, minimumX, maximumX );
Debug.Log(rotationY + " " + transform.localEulerAngles.x);
Debug.Log(rotationX + " " + transform.localEulerAngles.y);
That Debug.Log reveals a discrepancy between the rotation value and the actual Euler angle values. My key issue is that I need to find a way to align the values.
Main query:
I would like to find a way to correlate these angular values.
.
.
Further Explanation, stop reading here if no more information is required: After some averaging on the mouse input, later on in the script the transform is applied to the camera like so:
Quaternion yQuaternion = Quaternion.AngleAxis (rotAverageY, Vector3.left);
Quaternion xQuaternion = Quaternion.AngleAxis (rotAverageX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
I assume that the discrepancy comes from the way the angles are assigned in the above 3 lines. Where the rotationY value ranges between 60 and -60, transform.localEulerAngles.x ranges between 300 and 60 respectively.
The reason this discrepancy is a problem for me: during certain interactions, I force the player camera to look at an object using a Quaternion.Slerp(). Once this view-snapping is toggled off, the averaging function (responsible for mouse smoothing) has a tendency to snap the camera back to its initial rotation - thus, the values in the averaging function must be overwritten to match the camera's current resting position to prevent the odd rotation.
This for rotationX ( which corresponds to mouseX input sensitivity, and rotates around the Y axis). However, the discrepancy between the rotationY value (based on mouse input sensitivity) and the actual localEulerAngles.x makes it impossible to reset the camera at all using the values which I am currently working with.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Limit rotation Smoothly 2 Answers
Flip an object by 180° (C#) 0 Answers
how to get a correct rotation 2 Answers