Hi all
Im a South African 3D packaging and Product designer looking to learn unity. > unity rocks btw
Im currently busy with a learning project I’m having some trouble.
Basically I want a model viewer environment where my clients can view the models i create from all angles, zoom in, pan ect.
I have the zoom and pan working ok, and even rotating around the point on one axis is fine, but as soon as i add the other axis, it goes a bit mad and ends up rotating on the cameras z axis even though I locked the z rotation.
the reason for me using raycast is so the client can rotate around a specific part of a larger model [say the handle on a large cupboard].
Any help would be appreciated 
//Rotate point code
var ray : Ray = camera.ViewportPointToRay(Vector3(0.5, 0.5, 0));
var hit : RaycastHit;
var target = Vector3(0,0,0);
if(Physics.Raycast(ray, hit, Mathf.Infinity)){
target = hit.point;
}else{
target = targetObject;
}
//Rotate Action Code
transform.rotation.z = 0;
if(Input.GetMouseButton(0)){
//Change the angles by the mouse movement
var rotx = Input.GetAxis("Mouse X") * rotSpeed;
var roty = Input.GetAxis("Mouse Y") * rotSpeed;
transform.RotateAround(target, Vector3.up, rotx);
transform.RotateAround(target, transform.right, roty);
}
I posted a vehicle camera controller a while back… I hacked it up a bit to make it work for your situation… I set the target to be a place where you clicked, then you simply scroll around that target rather than try to play with rotations.
I didnt test it, not much time. Just post back and tell me if it worked or what part didnt. 
private var target : Transform;
private var newPosition : Vector3;
private var targetDamping = 2.0;
// for MouseWheel
var minDistance=5.0;
var maxDistance=40.0;
var zoomSpeed=10.0;
var distance = 15.0;
var defaultDistance=15.0;
var lastDistance=defaultDistance;
var distanceDamping = 2.0;
// from mouse orbit
var yMinLimit = -20;
var yMaxLimit = 80;
var rotationDamping = 3.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
private var x = 0.0;
private var y = 0.0;
function Start(){
target=GameObject().transform;
newPosition=target.position;
}
function LateUpdate(){
// work with the right camera
var cam : Camera= Camera.allCameras[0];
if(Camera.main){
cam = Camera.main;
}else if(Camera.current){
cam = Camera.current;
}
// if we click on the screen...
if(Input.GetButtonDown){
var ray : Ray = camera.ViewportPointToRay(Vector3(0.5, 0.5, 0));
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, Mathf.Infinity)){
newPosition = hit.point;
}
}
// move target to new position with damping
target.position = Vector3.Lerp (target.position, newPosition, targetDamping * Time.deltaTime);
// variables
var wantedRotationAngle=0.0;
var wantedHeight=0.0;
var currentRotationAngle=0.0;
var currentViewAngle=0.0;
var currentRotation:Quaternion;
// scroll wheel
distance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * 1000 * zoomSpeed;
distance = Mathf.Lerp (lastDistance, distance, distanceDamping * Time.deltaTime);
distance = Mathf.Clamp(distance, minDistance, maxDistance);
lastDistance=distance;
// MouseOrbit
var xx = Input.GetAxis("Mouse X");
var yy = Input.GetAxis("Mouse Y");
x += xx * xSpeed * 0.02;
y -= yy * ySpeed * 0.02;
currentRotation = Quaternion.Euler(y, x, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
cam.transform.position = target.position; // + Vector3(0,1,0);// a little above the target (do a center of bounds if you need to be in the center to begin with
// raycast test for distance -- removed
dist=distance;
//var hit : RaycastHit;
//if(Physics.Raycast(camera.position, currentRotation * -Vector3.forward, hit, distance)){
// dist=(hit.point-camera.position).magnitude - 1;
//}
// we could add a smooth out distance if it is not colliding.
cam.transform.position -= currentRotation * Vector3.forward * dist;
// Always look at the focalPoint
cam.transform.LookAt (target.position);// + Vector3(0,1,0) // add the lookat to the above or offset center point
}
Thanx very much for the quick reply. I’ll give your script a good look over in the morning as I have no internet at home 
I’ll be sure to let you know if it worked 
The commented out section for Racast Testing for distance. I think if you flipped it. Say started at 500 out and did a linecast back to the target then you could get the intersection with the model, and never cut the models pixels.
Also. In doing your demo, you could assign keys. So if the user presses 1, he goes to the default view position, 2 would be a closeup of something or another. You could find a way to incorporate the swapping of the camera and target from number to number and make it look smooth, that would be very cool.