Preventing Character Movement in Y Direction

Hello,

I’m trying to move the character with the camera using this code, but it also moves the camera in the Y direction the camera is looking. Is there a way I can move the character just in the X direction?

Thanks!

 void Update()
        {
            if (Input.GetKey(KeyCode.W))
            {
                transform.position = transform.position + (Camera.main.transform.forward * speed * Time.deltaTime);
            }

The following will remove the Y value from the camera’s view direction:

Vector3 cameraForward = Camera.main.transform.forward;

//Set Y to 0, and then normalize back into a direction.
Vector3 camXZForward =   new Vector3(cameraForward.X, 0, cameraForward.Z).normalized;

transform.position = transform.position + (camXZForward  * speed * Time.deltaTime);