How do I rotate my player and still make it go where I tilt my phone?

Ok, I’m not sure if I asked that right.

Anyhow, I’m making this 2d perspective game, one similar to that really old game “asteriods” where the camera is on top of the player. I use the accelerometer to move my player up, down, left and right. then I have 2 GUI buttons for rotating my player left and right. the problem is, when i rotate the player, the directions of the accelerometer gets ruined (for example, if i rotate the player then tilt the phone to the left, instead of the player going to the left, it goes to some other direction, which is very frustrating).

  • Is there anyway to rotate my player and still make it go where I tilt my phone?
  • Would someone explain to me what's the problem in the simplest way?
  • Can someone give me a sample code?

Sorry for being too demanding. I tried searching for answers and failed, so this is pretty much my last resort.

Here’s my code for the accelerometer:

var speed = 20.0;

function Update () {
	
	var xMove : float = -Input.acceleration.y * Time.deltaTime * speed;
	var yMove : float = Input.acceleration.x * Time.deltaTime * speed;
	
	transform.Translate(Vector3(xMove,yMove,0));
 	transform.position.x = Mathf.Clamp(transform.position.x, -Screen.width*0.045, Screen.width*0.045);
 	transform.position.y = Mathf.Clamp(transform.position.y, -Screen.height*0.045, Screen.height*0.045);
   	
} 

Here’s my code for turning:

function OnGUI () {

	if(GUI.RepeatButton(Rect(Screen.width * .01, Screen.height * .80, 50, 50), "<"))
	{
		transform.Rotate(0,0, rotationSpeed * Time.deltaTime);	 
	}
	
	if(GUI.RepeatButton(Rect(Screen.width * .20, Screen.height * .80, 50, 50), ">"))
	{
		transform.Rotate(0,0, -rotationSpeed * Time.deltaTime);
	}

Sounds like you want him to move by the world coordinates not his local coordinates.

Look at this

// Move the object upward in world space 1 unit/second.
    transform.Translate(Vector3.up * Time.deltaTime, Space.World);