Get rotation relative to camera

I am trying to check if a game object has been rotated past a threshold on a single axis and then do something if that threshold has been passed. However, I want to check the rotation relative to the main camera’s frame, not the parent or world frames.

How can I get the game object’s rotation relative to the main camera frame?

I tried using FromToRotation like this:

Quaternion diff = Quaternion.FromToRotation(Camera.main.transform.rotation, this.transform.rotation);

But FromToRotation takes in two Vector3 references and I only have quaternions.

I feel like I’m missing something simple, but I’m looking at the Quaternion API (Unity - Scripting API: Quaternion) and I don’t think any of these methods do what I want.

Any advice welcome!

FromToRotation takes 2 directions and not 2 rotations.

Quaternion.Angle looks like what you are searching for

You give it both rotation and it will give your angle between it.

If you just like to limit it to only one of the axis you coud do somting like this:

        // just checking the y angle in this case.
        Vector3 camY = new Vector3(0, Camera.main.transform.eulerAngles.y, 0);
        Vector3 objY = new Vector3(0, gameObject.transform.eulerAngles.y, 0);
        float diff = Vector3.Angle(camY, objY);