Set new default position each time?

First, I know it’s messy code, just bear with me, this is the first project that I was trying to avoid a lot of research so it’s a “Try what I know” kinda thing.

Second, So I have this bit of code :

   void Update()
    {

        if (Input.GetKey(KeyCode.W))
        {//If "W" Is Pressed, Go Forward .10f
            gameObject.transform.position += new Vector3(0, 0, 0.10f);
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {//If "Up Arrow" Is Pressed, Go Forward .10f
            gameObject.transform.position += new Vector3(0, 0, 0.10f);
        }



        if (Input.GetKey(KeyCode.A))
        {//If "A" Is Pressed, Go Left .10f
            gameObject.transform.position += new Vector3(-0.10f, 0, 0.10f);
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {//If "Left Arrow" Is Pressed, Go Left .10f
            gameObject.transform.position += new Vector3(-0.10f, 0, 0);
        }





        if (Input.GetKey(KeyCode.S))
        {//If "S" Is Pressed, Go Backwards .10f
            gameObject.transform.position += new Vector3(0, 0, -0.10f);
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {//If "Down Arrow" Is Pressed, Go Backwards .10f
            gameObject.transform.position += new Vector3(0, 0, -0.10f);
        }








        if (Input.GetKey(KeyCode.D))
        {//If "D" Is Pressed, Go Right .10f
            gameObject.transform.position += new Vector3(0.10f, 0, 0);
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {//If "Right Arrow" Is Pressed, Go Right .10f
            gameObject.transform.position += new Vector3(0.10f, 0, 0);
        }

}

Now if you run that, there are no bugs, except if you were to run it, then rotate whatever it’s attatched to, to something like 180 degrees, when trying to get forward, it will go backwards. (Because it’s in reverse due to 180)

I was just curious if there is anyway to make it so whenever you press the “UpArrow” // “W” it will always go forward.

Thanks in advance,
I hope this doesn’t go under “Asks for script”;
Also have a great day & Merry Christmas :slight_smile:

You can use transform.Translate () instead of assigning the position property.
It has an option for Space, use Space.Self, and it will always move in its own local coordinates.

Merry Christmas!