Mouse controls sometimes "bounces"

I want to build a bare-bones space flight/combat sim for class and I ran into some trouble with the mouse controls. I want the player avatar to "look" around using the mouse. The mouse-axes determine X and Y rotation. The problem is when I move the mouse too fast from the left to right (or vice versa), the camera will "bounce", as though it decided to move the opposite way before going the correct way. If I continually move the mouse extremely quickly, the bouncing motion will become more frequent. Here's the code snippet for my current mouse controls:

// Change cummulative rotation based on mouse input
cummulativeRotation.x -= Input.GetAxis("Mouse Y") * Time.deltaTime * rotationFactor;
cummulativeRotation.y += Input.GetAxis("Mouse X") * Time.deltaTime * rotationFactor;
// Create the target rotation from the cummulative rotatons
Quaternion targetRotation = Quaternion.Euler(cummulativeRotation.x, cummulativeRotation.y, 0.0f);
currentRotation = Quaternion.Slerp(currentRotation, targetRotation, ROTATION_DAMP * Time.deltaTime);

And the variables:

// Rotation
private Quaternion currentRotation;
private Vector3 cummulativeRotation;
public float rotationFactor = 200.0f;

// Dampening
private const float ROTATION_DAMP = 3.0f;

Just a note, I tried changing `rotationFactor` to 2000.0 and the bouncing effect was much more prominent. In fact I could not move my mouse at all without experiencing it. I assume the rpoblem lies with `Quaternion.Lerp` and how it treats angles but I'm not sure how to solve it. I tried implementing this with `Mathf.Lerp` and `Mathf.LerpAngle`. Both methods have the same problem. Any suggestions or alternative methods I could use would be appreciated.

3 Answers

3

Hello,

I’m getting exactly the same problem. Have you got any solution for that?

Thx.

Rafael

Hello,

try to change the value of ROTATION_DAMP or instead of using Time.deltaTime try Time.time.

Regards

Gava

Hello,

try to change the value of ROTATION_DAMP or instead of using Time.deltaTime try Time.time.

Regards

Gava