- Home /
Why does my mouselook sensitivity change depending on resolution? (C#)
I have this problem, I decided to build me game to see what it would look like, and I came across a problem, the mouse sensitivity changes depending on resolution, when on the lowest settings, it's too sensitive and on the highest settings it's not sensitive enough.
No errors or warnings display in the editor or on the built game.
How do I fix this?
If it helps, here's my code:
public enum rotationAxis {MouseX = 1, MouseY = 2}
public rotationAxis RotXY = rotationAxis.MouseX | rotationAxis.MouseY;
// X Axis
public float sensitivityX = 400f;
public float minimumX = -360f;
public float maximumX = 360f;
private float rotationX = 0f;
//Y Axis
public float sensitivityY = 400f;
public float minimumY = -50f;
public float maximumY = 50f;
private float rotationY = 0f;
public Quaternion originalRotation;
// Use this for initialization
void Start ()
{
originalRotation = transform.localRotation;
}
// Update is called once per frame
void Update ()
{
if (RotXY == rotationAxis.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
rotationX = ClampAngle(rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
if (RotXY == rotationAxis.MouseY)
{
rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
rotationY = ClampAngle(rotationY, minimumY, maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);
transform.localRotation = originalRotation * yQuaternion;
}
}
public static float ClampAngle (float Angle, float Min, float Max)
{
if (Angle < -360)
{
Angle += 360;
}
if (Angle > 360)
{
Angle -= 360;
}
return Mathf.Clamp(Angle, Min, Max);
}
}
Answer by asafsitner · Jan 20, 2013 at 01:44 PM
You don't need to multiply mouse input by Time.deltaTime
.
It seems like I do, because when I took it out, it became WAY too sensitivie!
That's because you multiply the input by 400 on each axis. Try it without multiplication at all.
I've converted it into an answer. "$$anonymous$$ouse X" and "$$anonymous$$ouse Y" already return delta values, so don't use Time.delta time in this case.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Unity's mouse look causing movement issues 1 Answer
How to disable MouseLook in ingame pause. 1 Answer
Disable JIT compilation in the Editor (Enable Full-AOT mode) 0 Answers
Character Not Rotating 0 Answers