G'day guys, second question post. I'll get right down to it, it's quite a dilema.
My scene contains a camera, controlled with the below script. The script allows the camera to be panned forward, backward, left and right with the keyboard, and by moving the mouse within 25px of a screen edge.
Here's the problem.
The camera is angled down by 45 degrees, which made it necessary to add Space.World to the end of the two lines of script that moved the camera forward or backward, to prevent it using it's own downard-facing Y axis. Now I'm trying to implement camera rotation (initially using the left and right mouse buttons for simplicity), the camera moves forward or backwards according to the global Y axis, meaning you can rotate the camera all you like, but you're always going the same direction.
I suppose an adequate mental aid might be imagining you are a tank that can rotate the turret, but can't change the direction.
You can move and rotate fine left and right of course, the X axis is 'self'.
I've been stuck on this for quite a while now. If I could fix it, I'd move on to replace mouse-button rotation with movement of the mouse while the right mouse is pressed. I suspect the real fix would involve finding a way to avoid using Space.World.
Sorry for a long post, but it's a real mongrel. Here's the code thus far.
private var myTransform : Transform;
private var scrollArea = 25;
private var scrollSpeed = 50;
function Update () {
myTransform = Camera.main.transform;
var mPosX = Input.mousePosition.x;
var mPosY = Input.mousePosition.y;
//Move camera with the arrow keys
transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"), Space.World);
//Move camera by moving the mouse to the edge of the screen, RTS-Style
if (mPosX < scrollArea) {myTransform.Translate(Vector3.right * -scrollSpeed * Time.deltaTime);}
if (mPosX >= Screen.width-scrollArea) {myTransform.Translate(Vector3.right * scrollSpeed * Time.deltaTime);}
if (mPosY < scrollArea) {myTransform.Translate(Vector3.forward * -scrollSpeed * Time.deltaTime, Space.World);}
if (mPosY >= Screen.height-scrollArea) {myTransform.Translate(Vector3.forward * scrollSpeed * Time.deltaTime, Space.World);}
//Rotate Camera left with LMB
if(Input.GetMouseButton(0))
transform.Rotate(0, 2.5, 0, Space.World);
//Rotate Camera left with RMB
if(Input.GetMouseButton(1))
transform.Rotate(0, -2.5, 0, Space.World);
}