# Finding the Screen Coordinates of the horizon when camera is rotating?

I have a GUI Line (GUITexture) that stretches across the screen attached to my player object. I also have the main camera parented to my player object. In its default position (with the camera facing forward) the GUI line divides the screen in half at Screen.height/2. There is a script attached to my player object that will rotate the camera up and down (positive and negative around the x-axis).

What I would like to have happen is that, when the player rotates the camera down (so that the center of the screen is now pointing in a downward angle), the GUI line stays on the horizon (at y=0 in the player's space, but not the camera's), meaning that the line would seem to rise up the screen until it is no longer visible (when the down angle gets large enough). How would I determine efficiently (especially since this is a GUI function and will be called multiple times a frame) where the original y=0 line is on screen to find out how high on the screen the GUI line needs to be drawn. Every idea I have come up with so far either requires an empty object to be created or rather dodgy mathematics. There must be a simpler way!

Thanks for any help!

I've figured it out. The code:

``````var linePos:float;  // y value of line

var tempLinePos: Vector3 = mainCam.WorldToScreenPoint(mainCam.transform.position+Vector3.forward*mainCam.nearClipPlane);
linePos = Screen.height - tempLinePos.y;

``````

linePos is the y value on the screen to place my line at. I then take the World to Screen point of a spot on the near clipping plane (Vector3.forward*mainCam.nearClipPlane) that corresponds to right in front of the camera. I then need to subtract it from the screen height (since camera and mouse/GUI y coordinates are inverted). Now the GUI line seems to stay static while the camera is rotating up or down.