- Home /
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.
Answer by gava100 · Feb 02, 2012 at 07:03 PM
Hello,
I'm getting exactly the same problem. Have you got any solution for that?
Thx.
Rafael
Answer by gava100 · Feb 03, 2012 at 12:18 PM
Hello,
try to change the value of ROTATION_DAMP or instead of using Time.deltaTime try Time.time.
Regards
Gava
Answer by gava100 · Feb 03, 2012 at 12:18 PM
Hello,
try to change the value of ROTATION_DAMP or instead of using Time.deltaTime try Time.time.
Regards
Gava
Your answer
Follow this Question
Related Questions
How can I Lerp the Rotation of my Game Object to my Mouse Pointer? 1 Answer
spinning an object with mouse movement 1 Answer
Smooth camera rotation on mobile and pc when GetMouseButton()? 0 Answers
How do I rotate Z axis based off mouse click and drag? 2 Answers
Problem with rotation script. 3 Answers