- Home /
How can I rotate my input axes 90º?
I have two input axes that are relative not to the player's current heading, but to a fixed view of a playing board: north-south and east-west. I want to be able to move my camera around the game board in 90º increments. So after a right rotation, North becomes East, East becomes South, South becomes West, West becomes North, etc., and after four moves, the controls and the camera are both back where they started.
How might I go about doing that? It seems like a much trickier problem than simply flipping an axis.
Answer by Bunny83 · Aug 05, 2011 at 10:58 PM
I guess you have a transform that is actually rotated by 90° ?
This transform have some nice properties: .forward / .right / .up which returns a normalized vector in world space.
Just use those to apply your input:
// UnityScript
var cameraTransform : Transform;
function Update()
{
var movement = cameraTransform.forward * Input.GetAxis ("Vertical") * speed;
movement += cameraTransform.right * Input.GetAxis ("Horizontal") * speed;
[...]
I'm going to just accept your answer because in the general case you're right; but I'm not moving the character directly from the input axes, it's something more complicated. I figured out that I need to have my own variables that I check in place of input.GetAxisRaw, and a function that first sets each of those variables based on another variable being set to 1,2,3,4.
Your answer
![](https://koobas.hobune.stream/wayback/20220612171433im_/https://answers.unity.com/themes/thub/images/avi.jpg)