Rough camera rotations

by Sonorhio   Last Updated January 14, 2018 02:13 AM

I'm doing a First Person Camera with Monogame. Moving the camera with WQSD works fine, but when I want to use my mouse in order to rotate the camera, the rotation is rough.

I'm doing this process : 1. Grab the last position of the mouse 2. Grab the current position of the mouse 3. Substract the current and the last position of the mouse 4. Set the mouse position in the center of my game window 5. Applying the X and Y value to my camera rotation matrix

When framerates are unlocked, everything's fine, when I don't set the mouse position everything's fine, but when i'm lock my framerates to 60 and I set the mouse position to the center, rotation is kind of rough, like not smooth at all... I can't figure out why.

Camera rotation code part :

        float deltaX = -Input.MouseCenterOffset.X;
        float deltaY = -Input.MouseCenterOffset.Y;

        Rotation.Y += deltaX * time;
        Rotation.X += deltaY * time;

Input code update :

        oldKeyboard = currentKeyboard;
        oldMouse = currentMouse;

        currentKeyboard = Keyboard.GetState();
        currentMouse = Mouse.GetState();

        OldMousePos = new Vector2(oldMouse.X, oldMouse.Y);
        MousePos = new Vector2(currentMouse.X, currentMouse.Y);

        SetCursor(Main.Width / 2, Main.Height / 2);

        MouseCenterOffset = MousePos - OldMousePos;
Tags : c# 3d monogame


Related Questions