Weapon recoil recoils in world space

weaponMesh.transform.position = Vector3.Slerp(new Vector3(weaponMesh.transform.position.x, weaponMesh.transform.position.y, weaponMesh.transform.position.z),
new Vector3(weaponMesh.transform.position.x, weaponMesh.transform.position.y, (weaponMesh.transform.position.z - recoilAmount)), recoilSpeed * Time.deltaTime);

I am using Vector3.Slerp to be able to add a recoil effect.

The problem is that, when I call this. (It is located in UPDATE, if the player is shooting.) it keeps adding the recoil in world space only.

*The weaponMesh is a child of the mainCamera, so it shouldn’t add the recoil in world space. Maybe I am using incorrectly de function? thanks, in advance.

Use the weapon transform’s forward Vector as the local z vector.
Also, the Vectors you pass can be written simpler.

weaponMesh.transform.position = Vector3.Slerp(weaponMesh.transform.position,
  weaponMesh.transform.position - weaponMesh.transform.forward * recoilAmount, recoilSpeed * Time.deltaTime);