Quaternions >.> ... Separate rotations (Pitch, Yaw, Roll)

I been working on my third person camera and am running into issues with rotations.

I want my camera to rotate around a pivot. The rotations can be up and down (pitch), left and right (yaw), or tilting left and right (roll). I also want my player to rotate the same as the yaw rotation.

So, I did something like this…

    void PitchRotation()
    {
        float pitchAmount = Input.GetAxis("Mouse Y") * 5f;
        pivot.Rotate(pitchAmount, 0, 0);
    }

    void RollRotation()
    {
        //Doesnt work since localEulerAngles.z seems to be giving eulerAngles in world space?
        //pivot.rotation = Quaternion.Euler(pivot.localEulerAngles.x, pivot.localEulerAngles.y, targetZRotation.localEulerAngles.z);

        //Works, but Pitch then does not work at all.
        //pivot.rotation = Quaternion.FromToRotation(pivot.up, targetZRotation.up) * pivot.rotation;
    }

    void YawRotation()
    {
        float turnAmount = Input.GetAxis("Mouse X") * 10f;
        pivot.Rotate(player.up, turnAmount, Space.World);
    }
//Somewhere on the player
transform.localRotation = Quaternion.Euler(transform.localEulerAngles.x, playerCamera.pivot.localEulerAngles.y, transform.localEulerAngles.z);
//Does not work if the player up axis is not the world up axis (he is rotated such as by walking on walls). Also, although I am using localRotation, regular rotation gives the same results..

The issues I am having are from when the player is rotated weirdly by walking on walls or something. The player trying to rotate to follow the cameras Yaw rotation will not work when the player is rotated on the z axis, and the Cameras pivot RollRotation will also not work.
The localEuler values werent what I thought they might act like, and by trying something like FromToRotation, it works, but then locks my pitch rotation…

I was able to fix the Roll problem by just using another transform to be the axis, and then having the pivot by a child of that, however, I still have the issue of my player not rotating properly.
Any help is appreciated =)

You can combine different Quaternions using the * operator:

transform.localRotation = Quaternion.AngleAxis(pitch, Vector3.right) * Quaternion.AngleAxis(yaw, Vector3.up) * Quaternion.AngleAxis(roll, Vector3.forward);

That code isn’t quite a real pitch-yaw-roll, because it’ll still be rotating around the world space axes instead of the axes as the rotations happen (which is probably only an issue for the roll part), but you can store each of those as a Quaternion and use “somequaternion * Vector3.forward” as the axis, too.

Hmm Im not sure if that is what I need.
If I want my player Local Y axis rotation to match some other objects Local Y rotation, without it affecting any other rotation, what do I do?
To use AngleAxis, I would need to get the angle needed to bring my players Y to the other objects Y. The problem is, I cant just do other.localEulerAngles.y - player.localEulerAngles.y to get the amount of angle needed to match the rotations as this only seems to work when the Z has no rotation.

Edit - kk I think I got something that works. Not sure if its overkill, but at least it seems to work.
This is what I am doing for my player to copy my cameras Y rotation.

Click for code

        void PlayerTurnRotation()
        {
            //We put our cameras forward local to our player forward so that we can be on the same plane when calculating the angle.
            Vector3 alignedCameraForwardDirection = ProjectForward(playerCamera.forward, player.up);
            float angle = AngleSigned(player.forward, alignedCameraForwardDirection, player.up);
            controller.transform.Rotate(0, angle, 0);
        }

        Vector3 ProjectForward(Vector3 direction, Vector3 upVector)
        {
            return Vector3.Cross(upVector, Vector3.Cross(direction, upVector));
        }

        float AngleSigned(Vector3 comparingVector, Vector3 compareToVector, Vector3 directionUp)
        {
            return Vector3.Angle(comparingVector, compareToVector) * LeftOrRight(comparingVector, compareToVector, directionUp);
        }

        float LeftOrRight(Vector3 comparingVector, Vector3 compareToVector, Vector3 directionUp)
        {
            Vector3 crossCompare = Vector3.Cross(comparingVector, compareToVector);
            float direction = Vector3.Dot(crossCompare, directionUp);

            if (direction > 0f) return 1f; //right
            if (direction < 0f) return -1f; //left
            return 0f; //forward or backwards
        }