How to prevent going up with camera movement system?

I have a rigidbody that has a FPS camera attached to it. How I make it move is by using this script I came up with :

void Move() {
		Camera cam = Camera.main;
		if (Input.GetKey(KeyCode.UpArrow)) {
			transform.Translate(cam.transform.forward * move_speed);
		}
		if (Input.GetKey (KeyCode.RightArrow)) {
			transform.Translate (cam.transform.TransformDirection(Vector3.right) * move_speed);
		}
		if (Input.GetKey (KeyCode.LeftArrow)) {
			transform.Translate (cam.transform.TransformDirection(Vector3.left) * move_speed);
		}
		if (Input.GetKey (KeyCode.DownArrow)) {
			transform.Translate (cam.transform.TransformDirection(Vector3.b) * move_speed);
		}
	}

Works pretty well, except when I look up, my player “jumps” up. How can I detect and cancel this movement? Thanks!

You can do it by being consistent with your code. I don’t know why you chose to do transform.forward instead of transform.TransformDirection when the latter worked out really well for you.

void Move() {
         Camera cam = Camera.main;
         if (Input.GetKey(KeyCode.UpArrow)) {
             transform.Translate (cam.transform.TransformDirection(Vector3.forward) * move_speed);
         }
         if (Input.GetKey (KeyCode.RightArrow)) {
             transform.Translate (cam.transform.TransformDirection(Vector3.right) * move_speed);
         }
         if (Input.GetKey (KeyCode.LeftArrow)) {
             transform.Translate (cam.transform.TransformDirection(Vector3.left) * move_speed);
         }
         if (Input.GetKey (KeyCode.DownArrow)) {
             transform.Translate (cam.transform.TransformDirection(Vector3.back) * move_speed);
         }
     }