How can i fix this

Here is my code :

public GameObject weaponStart;
public GameObject weaponEnd;
Vector3 newWeaponPosition;
Vector3 newWeaponPositionVelocity;
Vector3 defWeaponPosition;

private void Start()
{
    defWeaponPosition = transform.localPosition; // 0.2 -0.22 0.6
    newWeaponPosition = transform.localPosition;       
}

private void FixedUpdate()
{
    test2();
}

private void test2()
{
    RaycastHit hit;
    if (Physics.Raycast(weaponEnd.transform.position, 
        weaponEnd.transform.TransformDirection(Vector3.forward), 
        out hit, 0.1f, fpsController.playerMask))
    {
        Debug.Log("hit distance = " + hit.distance);
        float x = Mathf.Lerp(2, 0, hit.distance);
        newWeaponPosition = Vector3.SmoothDamp(newWeaponPosition, 
            new Vector3(newWeaponPosition.x, newWeaponPosition.y,
            newWeaponPosition.z - (x * Time.deltaTime)), 
            ref newWeaponPositionVelocity, 0.0f);
        transform.localPosition = newWeaponPosition;
    }

    else
    {
        if (Physics.CheckSphere(weaponEnd.transform.position, 0.05f, 
            fpsController.playerMask) || 
            Physics.CheckSphere(weaponStart.transform.position, 
            0.15f, fpsController.playerMask))
        {
            newWeaponPosition = Vector3.SmoothDamp(newWeaponPosition, 
                new Vector3(newWeaponPosition.x, newWeaponPosition.y, newWeaponPosition.z - 
                (10 * Time.deltaTime)),
                ref newWeaponPositionVelocity, 0.0f);
            transform.localPosition = newWeaponPosition;
        }

        if (newWeaponPosition.z >= defWeaponPosition.z)
        {
            return;
        }

        float y = Mathf.Lerp(2, 0, hit.distance);
        newWeaponPosition = Vector3.SmoothDamp(newWeaponPosition, 
            new Vector3(newWeaponPosition.x, newWeaponPosition.y, newWeaponPosition.z + 
            (y * Time.deltaTime)), 
            ref newWeaponPositionVelocity, 0.0f);
        transform.localPosition = newWeaponPosition;
    }
}

see jittering on gun. i want it smooth. if that’s possible.

Here is the problem :
1

ok the problem here is that your gun is an actual object you want to set it on a camera layer
here is a tutorial vvv