up/down with arrow keys

Hello, so im fairly new with unity and i have only just began learning to code javascript with it. I feel like I have learned a tremendous amount within one day however I have ran into an issue I cannot find a solution for. I created a square object and made it my camera for different testing purposes. I gave it a top down view with a 65rotation on the x-axis so its not a complete top down view. Im working on a script to pan the “camera” up, down, left, right. I made the left/right panning with ease however I cannot figure out the up and down panning mostly im guessing it will require some wild formula because the camera is not at a complete 90 rotation on the x-axis. Please help me with making it go forwards (up arrow key) and backwards (down arrow key). Here is my current script.

var ScrollSpeed = 2;

function Update () {
    if (Input.GetKey ("up"))
    {
  //transform.Translate(0, ScrollSpeed, 0);
    }
    if (Input.GetKey ("down"))
       {
          
        }
        if (Input.GetKey ("left"))
        {
        transform.Translate(-ScrollSpeed, 0, 0);
        }
        
        if (Input.GetKey ("right"))
        {
       transform.Translate(ScrollSpeed, 0, 0);
       }
}

This should help a lot: Unity - Scripting API: Input.GetAxis

You are moving the camera in local space. My guess is that you want to move in world space. To perform it just place another extra parameter in Translate (Space.World) so:

var ScrollSpeed = 2;

 

function Update () {

    if (Input.GetKey ("up"))

    {

  //transform.Translate(0, ScrollSpeed, 0);

    }

    if (Input.GetKey ("down"))

       {

          

        }

        if (Input.GetKey ("left"))

        {

        transform.Translate(-ScrollSpeed * Time.deltaTime, 0, 0, Space.World);

        }

        

        if (Input.GetKey ("right"))

        {

       transform.Translate(ScrollSpeed * Time.deltaTime, 0, 0, Space.World);

       }

}

Please note the “* Time.deltaTime”; It is necessary to assure that movement is frame rate independent.

Is this what you need?

Ah yes that makes perfect sense. I guess I didn’t need some crazy formula after-all. Thanks allot.