Moving an angled camera without affecting Y axis.

G'day guys, I'm pretty new to Unity (Flash convert), so I'm starting small and working on a few simple projects to teach myself the basics. A simple beginner's tutorial showed me how to create a camera, and move it along the X and Z axis, but once I angle the camera down 45 degrees, Z axis is now pitched towards the 'ground'!

I'm sure it's a simple matter of instructing the camera to move along an 'outside axis', not its own, but I can't find anything on the syntax for this. I'll paste my (simple) code below.

function Update () {
         transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

I hope to eventually develop this to become a response to the mouse hitting an invisible Gui object at the 4 edges of the screen, but this hurdle comes first.

If anybody could point me in the right direction, I'd appreciate it.


  • Stu

Ok I believe that you want something like this:

transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"), Space.World);

Inside the update function.

In the last part added it tells the translate function to use world space instead of local.

Hope this helps you and welcome to unity!