How can I get my first person plane camera to go upside down?

Hi there, first question on here. I’m messing around with the Programming intro tutorials and after I completed the plane game challenge I decided to have a little fun and try to implement a first person camera. I used code for a third person camera I had used before and modified it to place the camera on the nose of the aircraft, but when I rotate the plane above fully up or fully down, the camera starts returning to the horizon again without going upside down.

Here’s the code for my camera controller:

public class FollowPlayerX : MonoBehaviour
{
    public GameObject plane;
    private Vector3 sideOffset = new Vector3(50, 0, 0);
    private Vector3 frontOffset = new Vector3(0, 1.58f, 0.61f);

    private Vector3 sideRotation = new Vector3(0, 270, 0);
    

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("space")) {

            float desiredAngle = plane.transform.eulerAngles.x;

            Quaternion rotation = Quaternion.Euler(desiredAngle, 0, 0);

            transform.SetPositionAndRotation(plane.transform.position + (rotation * frontOffset), rotation);

        } else {
            transform.SetPositionAndRotation(plane.transform.position + sideOffset, Quaternion.Euler(sideRotation));
        }
    }
}

and here’s a link to the game. Just hold Space and either Up or Down until the plane goes into a loop.

I’ve tried adding +90 to the angle of rotation when plane.transform.eulerAngles.x goes above 0.5 or below -0.5 but that doesn’t work. I’ve tried multiplying the final rotation by * -1 when it passes those thresholds as well but no luck either. Any advice you could give would be appreciated. If you need more information, let me know.

after

transform.SetPositionAndRotation(plane.transform.position + (rotation * frontOffset), rotation);

Try putting

transform.LookAt(plane, Vector3.up);

I only bring in the transform you bring in GameObject so you may need to do

transform.LookAt(plane.transform, Vector3.up);