[SOLVED] Jitter with view model weapon sway

I am trying to have a weapon/arms model lag behind the rotation of the first-person camera.
I have direct mouse input controlling the camera, no mouse smoothing or frame rate dependency.

No matter how I put it I get a terrible jitter from the view model (THE CAMERA ROTATION IS FINE!):


This has nothing to do with character movement, it happens when standing still.

Here is the code:

    Vector2 newRot;
    public float sens;
    public GameObject viewModel;

    void Awake()
    {
        newRot = new Vector2(camTransform.eulerAngles.x, camTransform.eulerAngles.y);
    }

    private void Update()
    {
        newRot.y += Input.GetAxis("Mouse X") * sens);
        newRot.x -= Input.GetAxis("Mouse Y") * sens;

        newRot.x = Mathf.Clamp(newRot.x, -90f, 90f);

        // MOVE CAMERA
        camTransform.localRotation = Quaternion.Euler(newRot.x * lookSpeed, newRot.y * lookSpeed, 0);

        // Now here is where my problem is: I want to make the weapon follow the camera smoothly and delayed,             but it jitters badly


            // ROTATE VIEW MODEL
            viewModel.transform.rotation = Quaternion.Slerp(viewModel.transform.rotation, camTransform.rotation, .1f);

    }

I have tried:

  • Quaternion.Lerp instead
  • Changing the Slerp factor to Quaternion.Angle(camTransform.rotation, viewModel.transform.rotation) / float delayFactor
  • Moving the camera movement to LateUpdate(), and keeping the View Model code in Update()
  • Moving all of the code to LateUpdate()
  • viewModel.transform.rotation = Quaternion.RotateTowards(viewModel.transform.rotation, camTransform.rotation, Quaternion.Angle(viewModel.transform.rotation, camTransform.rotation));

  • viewModel.transform.rotation = Quaternion.LookRotation(Vector3.SmoothDamp(viewModel.transform.forward, camTransform.transform.forward, ref v, viewModel.rotateSpeed));

  • viewModel.transform.rotation = Quaternion.Slerp(viewModel.transform.rotation, camTransform.rotation, viewModel.rotateSpeed * Time.deltaTime);

Help is much appreciated. If it isn't against the rules I'll paypal ya $5 if you can fix it :)
Thanks!

Alright for anyone wandering that might have been having the same problem, I fixed this by making my view model a child of the camera. Then I made four animations for the view model holder that have one keyframe each, these are just the poses that represent the maximum allowed sway. SwayLeft, SwayRight, SwayUp, and SwayDown. In the view model animator controller, I set up a 2d freeform cartesian blend tree on a new layer that is additive. Then, through code, I lerped the parameters that control the blend tree.

Here's what my code looks like on update now: (note i've only set up the x sway atm)

float x = 0;

void Update(){
    if (aimingDownSights)
            {
                x = Mathf.Lerp(x, 0, .5f);
            }
            else
            {
                x = Mathf.Lerp(x, -Input.GetAxis("Mouse X") / 3, .03f);
            }


            if (animator != null)
                animator.SetFloat("Blend", x);
}

Anyways that solved my problem, kinda weird.