How to calculate input direction based on actor rotation and controller rotation?

guys i wanna calculate the direction player should move depending on where the controller is looking and where the character is facing.

so if the camera is looking from left side of the player and the player presses D the player should turn 180 degrees, and if the controller and the player are facing the same way and player presses W the player should just move forward.

how can I calculate this?

How’s that different for the standard third-person character?