Why is this moving in Z

Hi im trying to make a zooming funktion but when I run this code (see below) it moves the camera in both y and z.
I have tried to make a kinematic rigidbody and lock position in z but that did’nt help

if (Input.GetAxis(“Mouse ScrollWheel”) > 0)
{
Camera.mainCamera.transform.Translate(new Vector3(0, -movespeed * Time.deltaTime, 0));
}

else if (Input.GetAxis(“Mouse ScrollWheel”) < 0)
{
Camera.mainCamera.transform.Translate(new Vector3(0,movespeed * Time.deltaTime,0));
}

I have also tried to use Vector3.up and Vector3.down but that did not help either

I think your issue is the rotation of the transform. I would also try this,

transform.position += Vector3.up * movespeed * Time.deltaTime;

You can also do it with a lerp for a smoother movement.

Thanks it worked