0
\$\begingroup\$

I have a setup in unity using Graphics.DrawMesh() to draw a mesh on my players camera location in the update loop, Graphics.DrawMesh(viewModel, matrix, material, layer, null, 0); matrix = Matrix4x4.TRS(cam.transform.position, cam.transform.rotation, scaleFps); when I use my mouse to move around the camera, it lags behind where the camera is, as can be seen in the video. I have no idea how to fix this. I've tried not using the matrix, and it doesn't change anything.

https://youtu.be/eWFFYcOX_4Q

Here's the script I use for moving the camera:

    //Get the current mouse input.
    yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
    pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;

    //Clamp the camera rotation.
    pitch = Mathf.Clamp(pitch, -maxLookAngle, maxLookAngle);

    //Calculate and rotate the camera.
    currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, mouseSmoothScale);

    //Rotating the player.
    Vector3 bodyRotation = new Vector3(0, currentRotation.y, 0);
    transform.localEulerAngles = bodyRotation;

    //Rotating the camera.
    Vector3 cameraRotation = new Vector3(currentRotation.x, 0, currentRotation.z);
    playerCamera.transform.localEulerAngles = cameraRotation;'
\$\endgroup\$
  • \$\begingroup\$ Remember, we don't just need the code that moves the camera. We also need to see when that code is called. Are you doing each of these operations in Update, or is one in LateUpdate or even FixedUpdate? This is always important in a Unity question, so it's best if we never crop out the method itself. \$\endgroup\$ – DMGregory Jan 7 at 12:12
  • \$\begingroup\$ I fixed it by putting the render in lateupdate. \$\endgroup\$ – Stumpy Jan 7 at 23:13
  • 1
    \$\begingroup\$ That sounds like something worth posting as an Answer then! \$\endgroup\$ – DMGregory Jan 7 at 23:15
-1
\$\begingroup\$

I fixed it by putting the render in lateupdate.

\$\endgroup\$
  • \$\begingroup\$ This answer would be even better if it explained why this solves the problem. \$\endgroup\$ – DMGregory Jan 7 at 23:57

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.