Set input relative to map rotation?

Set input relative to map rotation?

I'm trying to figure out how I can make the input which looks like this : 
    // Checks if player is pressing movement keys, if is applies force to specified direction
    if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
    {
        //rigid.AddForce(new Vector2(-speed * Time.deltaTime, 0));
        rigid.AddRelativeForce(Vector2.left);
    }

    if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
    {
        //rigid.AddForce(new Vector2(speed * Time.deltaTime, 0));
        rigid.AddRelativeForce(Vector2.right);
    }

    if (Input.GetKey(KeyCode.UpArrow) && groundCheck.isGrounded == false || Input.GetKey(KeyCode.W) && groundCheck.isGrounded == false || Input.GetKey(KeyCode.Space) && groundCheck.isGrounded == false)
    {
        groundCheck.isGrounded = false;
        //rigid.AddRelativeForce(new Vector2(0, jumpPower));
        rigid.velocity = new Vector2(rigid.velocity.x, jumpPower);
    }

Always move according to the maps rotation.
So, even if the map were to rotate the player doesn't get inverted inputs (player is children of map, so it rotates too) : 
Right now A is always to left, according to the players position, but if the player would rotate 90 degrees the input would be wrong, Left would be up/down, but I want it to still be left.

Here's a picture example : (Sorry for the horrible painting, I blame mouse :> )


I do want the physics in the world to not change when I rotate the world.
So if the player is rotated 90 degrees it should fall to the side instead of down. :D

Solutions/Answers:

Answer 1:

The key is knowing current world rotation, you need to maintain it as you rotate e.g.:

double worldRotation;

void rotateWorldLeft()
{
   worldRotation = (worldRotation + 90) % 360;
}

then, when moving the character, just Rotate the Vector2s along e.g.:

if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
{
    rigid.AddRelativeForce(Vector2.left.Rotate(worldRotation));
}

Alternatively, if you have only few and known in advance possible rotations, you could use lookup table coupled with enum and modulus:

Enum Direction { Up = 0, Left, Bottom, Right }

Vector2[] Directions = { Vector2.up, Vector2.left, -Vector2.up, Vector2.right };

Direction worldOrientation; /*again keep it up-to date*/
...
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
{
   rigid.AddRelativeForce(Directions[((int)Direction.Left + (int)worldOrientation) % Directions.Length]);
}

note: the first solution should be preferred, casting enum to int is not the best practice – I am mentioning this only should you prefer avoid vector math completely

References