Change inputs to match camera direction

I have a system that will aways adjust the movement with a target in this function:

  public void HorizontalMovement(Transform target)
    {
        Rigidbody rigidbody = characterManager.rb;
       
        rigidbody.velocity = Vector3.zero;

        Vector3 inputDirection = characterManager.characterEngine.behaviourStack[0].directionStateData.localDirection;

        Vector3 up = rigidbody.transform.up.normalized;

        Vector3 backward = (rigidbody.position - target.position).normalized;

        Vector3 right = Vector3.Cross(backward,up);

        backward.y = 0;

        right.y = 0;

        Vector3 moveVectorHandler = Vector3.zero;

        moveVectorHandler = (inputDirection.x * right);
       
        moveVectorHandler += (inputDirection.z * -backward);

        rigidbody.velocity = moveVectorHandler * horizontalSpeed;

    }

works very well for AI, but im trying to add a player controller above all that.
i want that foward is foward in relation to the camera, not in relation to the target, but i cant remove the target, so i need to adjust the inputs before and my math skills are very limited

this is the player scrip part that will modify the inputs before i send to the script that will move the player:

    private void Update() {
       
        inputHandler.UpdateWithPlayerInputs();

        UpdateMoveInputsRelativeToCamera();

        characterManager.characterEngine.OvewriteBehaviour(behaviourFabric.CreateBehaviour(target.transform,inputHandler.directions,0,0));

    }

    public void UpdateMoveInputsRelativeToCamera() {

        Vector3 direction = Vector3.zero;

        Vector3 up = transform.up;

        Vector3 foward = -(transform.position - target.transform.position).normalized;

        Vector3 right = Vector3.Cross(foward,up);

        Vector3 camFoward = camTransform.forward;

        Vector3 camRight = camTransform.right;

        camFoward.y = 0;
        camRight.y = 0;

        foward.y = 0;
        right.y = 0

        //i have no ideia what to do

        direction.Normalize();

        inputHandler.directions.x = direction.x;
        inputHandler.directions.y = direction.z;
       
    }

thanks for everyone, and sorry if something is unclear my english is not very good, and dont know exactly how to explain this problem

Here’s the sauce:

https://github.com/kurtdekker/proximity_buttons/blob/master/proximity_buttons/Assets/DemoCameraRotatedControls/RotatedControlsPlayerController.cs

Go to line 124 to 128 where the magic happens to the inputs, making them face the camera direction.

Above script is used in the DemoCameraRotatedControls scene

Done!! a lot of try and error, if someone has a better solution i will be gratefull to see, i still a little lost with the exact math behind but i know the idea

 public void UpdateMoveInputsRelativeToCamera() {

        Vector3 direction = Vector3.zero;

        Vector3 up = transform.up;

        Vector3 foward = -(transform.position - target.transform.position);

        Vector3 right = Vector3.Cross(foward,up);

        Vector3 camFoward = camTransform.forward;

        Vector3 camRight = camTransform.right;

        camFoward.y = 0;
        camRight.y = 0;

        foward.y = 0;
        right.y = 0;

        Vector3 moveVectorHandler = Vector3.zero;

        float angle = Vector3.Angle(camFoward,foward);

        direction.x = inputHandler.directions.x;
        direction.z = inputHandler.directions.y;

        direction = Quaternion.AngleAxis(angle, Vector3.up) * direction;

        direction.Normalize();

        inputHandler.directions.x = direction.x;
        inputHandler.directions.y = direction.z;
       
    }

thanks i will check