if you dont want it to leave the terrain then you can use this.
i use it in mine.
simple and easy, three paramters;
CamId = <CameraId>
x = <Max distance from 0>
y = <Max distance from 0>
void CameraKeepInBox (int CamId , int x , int z )
{
//in box?
if (dbCameraPositionX ( CamId ) < 0 )
{dbPositionCamera ( CamId , 0 , dbCameraPositionY(CamId) , dbCameraPositionZ ( CamId ) );}
if (dbCameraPositionX ( CamId ) > x )
{dbPositionCamera ( CamId , x, dbCameraPositionY(CamId) , dbCameraPositionZ ( CamId ) );}
if (dbCameraPositionZ ( 1 ) < 0 )
{dbPositionCamera ( CamId , dbCameraPositionX ( CamId ) , dbCameraPositionY(CamId) , 0 );}
if (dbCameraPositionZ ( 1 ) > z )
{dbPositionCamera ( CamId , dbCameraPositionX ( CamId ) , dbCameraPositionY(CamId) , z );}
}
im working on a terrain example so things like this are easy to understand
Problem Solution That Never Fails: "Build A Bridge And Get Over It"