# How to circle an uneven object with Camera at a fixed distance?

Unity3d. I am trying to move an object with Camera around a fixed terrain (Mountain), while staying an set distance from its edge. I have the camera set to lookAt the mountain, and I want to circle the mountain. I was thinking about sine wave for circular motion but its not an exact circle as I need to move in or out to maintain the fixed distance from the mountains edges.

It looks like I might need transform.RotateAround(..), but what about the adjusting to maintain a fixed distance from the edge of the uneven surface while maintaining the circular motion.

    transform.RotateAround (Vector3.zero, Vector3.up, 20 * Time.deltaTime);


Update: Here is my current script for circling around mountain as first person object:

function Update () { var mountain : GameObject; mountain = GameObject.Find("QuantumCold_B"); transform.RotateAround(mountain.transform.position, Vector3.up,20 * Time.deltaTime);

}

Unfortunately there are two problems:

1) The first person object appears to be falling or maybe its the main camera, but in any even there is a game screen looks like its falling below the mountain. 2) it is the mountain that seems to be rotating. Do I need to switch the main camera to be the first person camera. Why does the mountain appear to be rotating?

• You should post some code to work with and not to expect getting all done for you. Show what you have and how you have tried to do it. That would make answering easier. – Katu Jul 22 '13 at 18:31
• I don't think you need to show much code. I do think you need to define what you mean by the "edge" of the mountain. It's trivial to set up orbiting around a single fixed point, but it sounds like what you want is to orbit around a contour such that you are always a fixed distance from that contour, so it's important to indicate what that contour is. – user1430 Jul 22 '13 at 18:34
• Its a mesh called from Quantum Cold. – gitright Jul 22 '13 at 22:30
• I don't really like using RotateAround() because that only works right when the target is still. I mean, in this case the target is still, but then you'll get used to doing it this way. You can also orbit the camera by storing an offset position, multiplying that offset by the rotation to get a rotated offset, and then add the rotated offset to the target position. The code (with _rotY incrementing every frame) Quaternion rotation = Quaternion.Euler(0, _rotY, 0); transform.position = target.position - (rotation * _offset); transform.LookAt(target); – jhocking Jul 18 '14 at 11:36
• also, you shouldn't use GameObject.Find() every frame. Instead do it once in the Start() function and then store the result in a variable. – jhocking Jul 18 '14 at 11:49

cameraPosition += -ray.Direction * (distanceIwantMyCameraToBe - intersectionTestResult);