Camera pitch/yaw relative to plane

I'm developing an astronomy/planetarium application in Unity and I've come across a problem.

I need to set the camera pitch/yaw (altitude/azimuth) relative to a ground plane (so the 'horizon' is always parallel to the bottom of the screen). The cameras parent transform is the ground plane and if I adjust the local rotation of the camera on either the horizontal or vertical axis, it seems to work, but if I adjust both at the same time, the camera twists and the 'horizon' rotates.

I'm sure I'm missing something here and I've searched on the forum for an answer, but nothing seems to work. Although I'm not new to programming, I'm fairly new to 3D programming so a little nudge in the right direction would certainly help me out. :-)

Well, i guess Transform.Rotate will do the job. The default space is local space, so it rotates around the local axis.

I don't get your camera problem. If the camera is a child of your plane it will move and rotate with the plane whatever the plane is doing. Or in other words: What should your camera do? If you want a smooth following camera don't add it as child. There's a smoothFollow script in the standard assets that would do the job.


edit

Ok if i got that right your camera is mounted at the center (like in a planetarium) and there’s some kind of hemisphere around your camera. Now you want to turn/pitch the camera to look at a certain point by giving the heading(azimuth) and a pitch(polar angle/altitude). Well to accomplish such a rotation you have to keep in mind that if you rotate the camera around the local x axis, the local upvector will tilt. So the azimuth angle have to be applied globally. If your whole scene is stationary you can just use Rotate with Space.World. If your “plane” can move/tilt you have to use RotateAround with the up vector of your plane.

transform.RotateAround (transform.position, transform.parent.up, azimuth);
transform.Rotate (altitude, 0, 0);

The two angles here are delta values. If you want to setup a rotation with absolute angles just use a Quaternion:

transform.localRotation = Quaternion.Euler (altitude, 0, 0) * Quaternion.Euler (0, azimuth, 0);

If i don't messed up the order that should work ;)

well by the looks of things u are using what the guy below has said. if ican explain things in 1 word that would be the Gimbal lock effect basically its when the camera is trying to find 2 axes in a 3d space and it rotating around around them it doesnt simply rotate around both at the same time it works on 1 ie the x then the y then the z axis so when both rotate it may come outt that the camera is turned in to a human rolercoaster this can also be explained by what the guy above has offered being the eualer which is basically a follow but when say in a flight sims case the players plan flips because the object always wants to not excede the 90 degree mark. what you need to do is remove it. im not sure but a while ago there was 1 on this forum. try searching for how to fix camera fliping or something of that nature. if you do not wish to go to that effert you could simply make a max rotation angle so the player doesnt flip do an if statement like

planatarium roation style if (object>objectanglerotation.x) {objectanglerotation.x}