Gun recoil - Gun positioning itself at the 0,0,0 coordinates

Hello I have a bit of problem.

I’ve managed to create a recoil for my gun.

But when i start the game , the gun automaticly snaps itself to the gunHolder gameobject (coordinates 0,0,0 )
When i shoot the gun animates the recoil.

I’ve tried replacing the transform.localPosition with transform.position and Vector3.zero with transform.position didn’t worked the gun still snaped itself to the 0,0,0 coordinates

Does anybody knows how to fix this ?

Here is my code feel free to use it.

    [Header("Atributes")]
    public float fireRate = 0.25f;


    [Header("Recoil")]
    public Vector2 kickMinMax = new Vector2(.05f, .2f);
    public Vector2 recoilAngleMinMax = new Vector2(3, 5);
    public float recoilMoveSettleTime = .1f;
    public float recoilRotationSettleTime = .1f;

    Vector3 recoilSmoothDampVelocity;
    float recoilRotSmoothDampVelocity;
    float recoilAngle;

    float nextFire;

    private void Update()
    {
        if (Input.GetMouseButton(0) && Time.time > nextFire)
        {
            Shoot();
        }

        //RECOIL//
        transform.localPosition = Vector3.SmoothDamp(transform.localPosition, Vector3.zero, ref recoilSmoothDampVelocity, recoilMoveSettleTime);
        recoilAngle = Mathf.SmoothDamp(recoilAngle, 0, ref recoilRotSmoothDampVelocity, recoilRotationSettleTime);
        transform.localEulerAngles = Vector3.right * -recoilAngle;
    }

  

    void Shoot()
    {
        nextFire = Time.time + fireRate;

        //RECOIL//
        transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
        recoilAngle += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
        recoilAngle = Mathf.Clamp(recoilAngle, 0, 30);

    }

}

When you say it snaps to the gun holder at 0,0,0 - is that a local position? Where should it be if not there?
From your code it looks like your smoothdamp is doing that. Looks like it would go back there after whatever recoil happens, too?

I’ve never tried this, but it seems reasonable that perhaps an animation or coroutine could do this for you, as well. Not saying you should change or not solve this, just offering some options.

I would think it’s the Vector3.zero in the first smoothdamp, which maybe should be Vector3.forward * some fraction. You probably want the gun out from the zero position, even if it’s local because that would be the center of the body.