# MouseOrbit script in alternate space

Unhappy with my previous results I am now using the MouseOrbit script from the wiki.

Unfortunately my environment differs a bit from the assumptions in the script, in that the view is always from the top (e.g. Z = -50) on the X/Y grid (RTS style). The script assumes that one is operating in an environment where one is looking towards Z.

I don’t know why but for the love of Christ I cannot adapt the script to work in my alternate space… it doesn’t seem to be as simple to just change the axes - the rotations are all screwed up… any ideas?

Here the script:

x += Input.GetAxis("Mouse X") * 10f * distance * 0.02f;
y -= Input.GetAxis("Mouse Y") * 10f * 0.02f;

y = ClampAngle(y, yMinLimit, yMaxLimit);

Quaternion rotation = Quaternion.Euler(y, x, 0);

distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);

Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.transform.position;

transform.rotation = rotation;
transform.position = position;

Well, Unity’s usual space is like this. It uses a left-handed system where +z is forward +x is right and +y is up. You’re of course not bound to this, but it simplifies a lot when you stick to this system. So for an rts game you would use the x-z plane as ground.

However, it your game is already setup with x-y as ground and -z as up (+z down), you can juse change:

transform.rotation = rotation;

to

transform.localRotation = rotation;

and parent this object to an empty gameobject which is rotated downwards (x rotation == 90/-90).