Cinemachine FPS cam making movement weird

I created a Cinemachine FPS camera by following these directions:

SETTING UP AN FPS CAMERA
-Create an empty object that we will call head object and parent it to the player. This should be where the players head should be so position it so.
-Download cinemachine plugin and insert a cinemachine camera into your scene.
-Set it’s target to your head object, then set the position control to “Hard Lock To Target”
-Set the rotation control to “Pan Tilt”
-At the botton add an axis input controller
-Change the gain value in the axis input controller to change the sensitivity of your screen movement(+x,-y)

After Implemented the camera, the movement starting being weird. I was no longer moving in the direction I wanted to go.

I eventually found a fix without really understanding what the issue was.

MOVEMENT CODE(PRE-CINEMACHINE 3.1.2)

public void ProcessMove(Vector2 Input)
{
    Vector3 moveDirection = Vector3.zero;
    moveDirection.x =  Input.x;
    moveDirection.z = Input.y;
    characterController.Move(transform.TransformDirection(moveDirection) * Speed * Time.deltaTime);
    playerVelocity.y += gravity * Time.deltaTime;
    if (isGrounded && playerVelocity.y < 0)
        playerVelocity.y = -2;
    characterController.Move(playerVelocity * Time.deltaTime);
    Debug.Log(playerVelocity.y);
        
}

MOVEMENT CODE(POST-CINEMACHINE 3.1.2)

 public void ProcessMove(Vector2 Input)
 {
     Vector3 moveDirection = playerCam.transform.forward*Input.y+playerCam.transform.right*Input.x;
     //moveDirection.x =  Input.x;
     //moveDirection.z = Input.y;
     characterController.Move(moveDirection * Speed * Time.deltaTime);
     playerVelocity.y += gravity * Time.deltaTime;
     if (isGrounded && playerVelocity.y < 0)
         playerVelocity.y = -2;
     characterController.Move(playerVelocity * Time.deltaTime);
     Debug.Log(playerVelocity.y);
         
 }

Does anyone have any clue why this is happening? If it helps my old fps camera was just parenting the camera to the player object and updating it’s rotation based on the moue input.

I believe this weird behavior you mention likely happens when the camera’s orientation isn’t properly aligned with the player’s forward direction. I had the same issue, and I fixed it in the same way.

private void Move()
{
    // Using the camera's right and forward vectors ensures movement is relative to the camera's direction.
    Vector3 moveDirection = (mainCamera.transform.right * movementDirection.x + mainCamera.transform.forward * movementDirection.y).normalized;

    // Preserve the vertical component of the rigidbody's velocity (gravity, jump) while applying horizontal movement.
    moveDirection.y = rigidbody.linearVelocity.y;

    // Apply the movement direction to the rigidbody's linear velocity, scaling it by the movement speed.
    rigidbody.linearVelocity = moveDirection * speed;
}