#Camera rotation flick from time to time

1 messages · Page 1 of 1 (latest)

kind mulch
#

I'm writting a really basic character controller, and almost so far so good. But my camera movement script has some issue with rotation. From time to time when moving around, the rotation seems to "reset", or at least to go to the (0, 90, 0) coordinates (or whatever round value around 0, 90, 180 and their negative counterpart).

I'm using a basic script :

        private void CameraLook()
        {
            float mouseX = playerController.LookDelta.x * mouseSensitivity * Time.deltaTime;
            float mouseY = playerController.LookDelta.y * mouseSensitivity * Time.deltaTime;
            
            _rotation.y += mouseX;
            
            _rotation.x -= mouseY;
            _rotation.x = Mathf.Clamp(_rotation.x, -90f, 90f);
            
            Quaternion targetRotation = Quaternion.Euler(_rotation.x, _rotation.y, 0);
            
            // transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, mouseSensitivity * Time.deltaTime);
            transform.rotation = targetRotation;
            
            targetRotation = Quaternion.Euler(0, _rotation.y, 0);
            // playerController.orientation.rotation = Quaternion.Slerp(playerController.orientation.rotation, targetRotation, smoothSpeed * Time.deltaTime);
            playerController.orientation.rotation = targetRotation;
        }

with LookDelta being the mouse value getted from the Move event in the new input system. I guess my problem is from the fact that i'm using Quaternion.Euler and that isn't really partical, but I have no other solution rn.

Thanks for your time !

#

note: the script is attached to my camera, and playerController to my player. My camera isn't a child of my player

astral beacon
#

Why do you multiply mouse delta by time.deltatime

kind mulch
#

good question, old habit to do that with user inputs used every frames

#

but I don't think this cause any problems here

astral beacon
#

but anyways

kind mulch
#

yes, this is not my question

astral beacon
#

So the y rotation resets

#

Is this for the camera or the player?

kind mulch
#

The camera it seems

#

it looks like a gimbal lock to me

#

but i never needed to fix one before so I'm not sure on how to

astral beacon
#

You can try clamping the x rotation to between -89.9 and 89.9

#

it's slightly ugly (for some ppl) but will ensure that your axes don't degenerate

kind mulch
#

it did the same

astral beacon
#

and you say the rotations are multiples of 90?

astral beacon
kind mulch
astral beacon
#

...

#

Firstly, that's the x rotation lol

#

And the flick occurs when your framerate drops

#

An incorrect use of time.deltatime could cause this issue

kind mulch
#

if was indeed deltaTime, sorry for the confusion and for contradicted you

astral beacon
#

ah no worries, it happens, and I'm not completely sure that's the issue

#

I'd try tho by removing the multiplication of time.deltatime from your mouse x and y calculation (you may need to adjust sensitivity after the change)

#

Another way to see if time.deltatime is incorrect is to cap your framerate at like 60 fps and see if the mouse sensitivity changes. If it does, that indicates you're using deltatime incorrectly

kind mulch
#

I had no issues since I removed it, and it was almost consistent beforehand

#

So I guess thats good enough

astral beacon
#

Just reading the docs on the new input system, it seems like the mouse delta value is accumulated over multiple events, so the delta represents an absolute change in position, so as long as that delta is being reset after you read it, there's nothing that indicates you need to multiply by dt