Hello!
I am facing a weird problem with my mouse input. I am currently improving my mouse look script, but it seems that my new computer mouse is not working correctly with the script. When I am starting a build version of the game, my Player keeps spinning around itself, even if I am not moving the mouse at all.
The problem only occurs when I am using the 3DConnexion CAD mouse. If I switch back to my old Logitech one, the game doesn’t have this behaviour at all and the script is working as intended. Is this a bug in Unity or am I doing something wrong script wise?
Here is the mouse look script (I am leaving out some parts which are not related to the mouse movement):
public float LookSmoothDamp = 0.1f;
public float LookClampBottom = 35f;
public float LookClampTop = 55f;
public float LookSensitivity = 5f;
private float rotX = 0.0f;
private float rotY = 0.0f;
private float currentXRotation;
private float currentYRotation;
private float xRotationVelocity;
private float yRotationVelocity;
private float rotationY = 0.0f;
private float rotationX = 0.0f;
void Update()
{
// Get Inputs
rotationX = Input.GetAxis("Mouse X");
rotationY = -Input.GetAxis("Mouse Y");
}
void FixedUpdate()
{
switch (ControlMode)
{
case ControllerMode.FirstPersonFly:
Rotate(rotationY, rotationX);
break;
}
}
private void Rotate(float x, float y)
{
rotY += rotationX * LookSensitivity;
rotX += rotationY * LookSensitivity;
//Weichen Übergang hinzufügen
currentXRotation = Mathf.SmoothDamp(
currentXRotation,
rotX,
ref xRotationVelocity,
LookSmoothDamp
);
currentYRotation = Mathf.SmoothDamp(
currentYRotation,
rotY,
ref yRotationVelocity,
LookSmoothDamp
);
//Sichtradius in X einschränken
rotX = Mathf.Clamp(rotX, -LookClampTop, LookClampBottom);
var camTransform = currentCamera.GetComponentInChildren<Camera>().transform;
currentCamera.transform.forward = new Vector3(
camTransform.forward.x,
0.0f,
camTransform.forward.z
);
camTransform.rotation = Quaternion.Euler(
currentXRotation,
currentYRotation,
camTransform.rotation.z
);
}