Make camera hover at 50 over hilly terrain

Hi i am very new to unity and am currently concentrating on different camera scripts for an RTS type game. Currently when i press tab my camera zooms in and moves from a height of 200 to 50 and changes rotation. However at the height of 50 when i move the camera sometimes it goes into mountains and i was wondering if there was a way of making it hover at a constant height of 50 above the terrain. I started work on a script using Raycast (as seen below) but i don't no if I'm anywhere near the answer

var hit : RaycastHit;

function Update () {

if(Physics.Raycast (transform.position, -Vector3.up, hit)) {
    if(hit.distance < 50)
        transform.Translate(Vector3(0, 1, 0) * Time.deltaTime, Space.World);
}

}

Any help would be much appreciated, Thanks

var hit : RaycastHit;

var mTransform : Transform;

function Start () {
    mTransform = transform; /* searching for the object's transform component
                               every update frame especially multiple times is
                               slow according to the [docs](3rd point)[1]*/
}

function Update () { 
    if(Physics.Raycast(mTransform.position, -Vector3.up, hit))
       if (hit.transform.tag == "ground")) {
            mTransform.position.y =
                 hit.point.y + expectedHeightFromGroundBasedOnZoom;
            // expectedHeightFromGroundBasedOnZoom would be 50 in your example
       }
}

This way your camera will be exactly `expectedHeightFromGroundBasedOnZoom` distance units away from the ground on the Y axis.

Use this, there were a few mistakes in that original code. With this script I have also included camera smoothing so that movement is not so jerky.

#pragma strict

var hit : RaycastHit;

var mTransform : Transform;
/*EDIT THESE SETTINGS*/
private var cameraHoverHeight = 50;
private var terrainName = "Terrain";
/*------------------------*/

/*DON'T EDIT THESE SETTINGS*/
private var yVelocity = 0.0;
/*------------------------*/
function Start () {
    mTransform = transform; 
}

function Update () { 
var smoothTime = 0.2/(camera.velocity.magnitude/100);


    if(Physics.Raycast(mTransform.position, -Vector3.up, hit))
       if (hit.transform.name == terrainName) {
       
       var newPosition : float = Mathf.SmoothDamp(transform.position.y,  hit.point.y + cameraHoverHeight,
                                 yVelocity, smoothTime);


   transform.position = Vector3(transform.position.x, newPosition, transform.position.z);
       
    }   
       
}