The desired result:
A camera that follows a player or object as it moves, doesn't automatically rotate with the object's own rotation. Is capable of orbiting around the player's Y axis via left and right arrow keys. Is capable of orbiting around the player's X and Z axis to produce a change from top down to side on view via the up and down arrow keys regardless of current rotation around the Y axis. Is clamped to only being able to go directly above the player or directly horizontal to the player so that the player does not become upside down or the map invisible as it is viewed from underneath. Zooming with the scroolwheel also desired.
Currently Completed :
Rotation around Y axis
transform.RotateAround (player.transform.position, Vector3.up,2*Input.GetAxis("Horizontal"));
Following the player's position without being a child of the player (thus avoiding auto following player model rotation).
playerMoveOffset = player.position - playerPrevious; //all Vector3 variables, work out difference between player position now and previous
transform.position += playerMoveOffset; //transform belongs to camera, move camera equal to amount player moved since last update
playerPrevious = player.position; //set latest player location
The issue:
I have only managed to get the up and down motion working on a single axis at a time, rotating around the Y axis and attempting to rotate both axis at the same time to give the proper effect becomes skewed due to the difficulty in managing the different euler values, quaternions and other nonsense that one has to deal with when manipulating unity rotations.
The concept was to determine the ratio between X axis rotation and Z axis rotation needed to get a clean vertical line from any angle, then multiply the speeds of those rotations by that ratio. I came very close with the following
var x = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).x + 180; // value from 0 to 360
var y = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).y + 180; // value from 0 to 360
var z = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).z + 180; // value from 0 to 360
var zMod180 = z % 180; //values from 0 to 1 are positive, values form 1 to 2 are negativet
var zMod90 = z % 90 ; //determines % of forwards:left backwards:right
Debug.Log (zMod90);
transform.RotateAround (player.transform.position, Vector3.left,(90-zMod90)/90*2*Input.GetAxis("Vertical"));
transform.RotateAround (player.transform.position, Vector3.forward,zMod90/90*2*Input.GetAxis("Vertical"));
This was my latest attempt which is incorrect. I do not have, nor would it be appropriate to post my other attempts as it constitutes hundreds of lines of failed code.
Assistance working out the final part of this camera script would be greatly appreciated.