I'm slowly but surely piecing together a basic 'RTS-Style' Camera, with the current code allowing panning by moving the mouse to screen edges, panning with arrow keys, and I've tried a few different techniques of rotating the camera.
What I'd like to implement is a method of orbiting the camera around the area it's looking at. The camera is tilted down 45 degrees, so I imagine it could be as simple as orbiting around a location that is its current location, minus Z and Y ( z = -32 and y = 27 by my measurements).
Ultimately I'd like to do this by mouse drag. I've searched Unity Answers and the Scripting Reference, but can't seem to find anything. Does anybody have any idea where I might find useful information on what I'm after?
Though I've never tried implementing what you're after, you should be able to use Transform.RotateAround to achieve the orbit effect (with the position that you've already calculated). The Input EventType.MouseDrag will occur when the mouse was moved with a button held down. Use mouseDelta to return a Vector2 of the mouse movement, and apply that Vector2 to the camera 'orbit'.
Hopefully this sets you on the right track - if you have any troubles, please post back (with whatever code you have). Cheers!
Updating based on comments below:
private var targetPosition : Vector3;
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
targetPosition = transform.position;
targetPosition += transform.forward * 27;
}
if (Input.GetMouseButton(0))
transform.RotateAround(targetPosition,Vector3.up,50*Time.deltaTime);
}
With this code, when you first press the mouse button, it calculates and stores the targetPosition. Every frame where the mouse button is held, the transform position orbits around the calculated position.
It's not perfect - there are some inaccuracies due to floating point calculations. You could clamp/handle the values that you never want to change (most likely, the x and z rotational values).