Android tilt controls - adjusting to player's perspective

Hi,

I’m having an issue with my game with the tilt controls. I’ve got the tilt controls working initially but when the player turns 90 or -90 degrees (I have made a game similar to temple run with the movement, the player is always running and a screen swipe will rotate the player + or - 90 degrees), the tilt controls continue to control the same way, so the player will just run faster or slower rather than left or right. I understand why this happens - the code just takes into consideration one axis’ tilt and controls the player in the same way. I’m just really unsure how to change this for what I need.

How can I change this so that the tilt controls will affect the way the player is facing rather than generally? I feel this may be something more obvious but I’ve been thinking a lot and have done lots of research to no avail.

Here is my code segment for the tilt movement at the moment (javascript), just very basic:

    direction.x = Input.acceleration.x * moveSpeed;
     
    if (direction.sqrMagnitude > 1)
    direction.Normalize();
     
    // Make it move 10 meters per second
    direction *= Time.deltaTime;
     
    // Move object without transform to take boundaries into consideration
    controller.Move (dir * speed);

Any help with this would be greatly appreciated. Thanks.

Shameless bump but any ideas? I’m still stuck on this part and would love to sort it. Thanks.