# Unity3D - Change player input axes on trigger

Hope someone can help me with this, it seems like it should be a simple problem but that only makes it more frustrating!

I have a simple game where you roll a ball around by applying force to the horizontal and vertical axes. What I want to happen is, on a trigger, the axes switch from say the X and Y, to the X and Z, changing the way the player controls without changing the input buttons... The script I use to move the player is below:

{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");

Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}


(Where rb is the player ball object) - I'm thinking I'm going to have to change the way the player is controlled as I can't any reference to a 3rd axis in the Input.GetAxis documentation... any help with this would be great!

Thanks!

• So your Vector3 movement code is probably the what needs to change if you want the player controls to be the same but the movement to be different. Right now you are applying the movements to the (horizontal, 0f, vertical) positions, if you want to make the vertical movement affect the y axis instead then it needs to be new Vector3(horizontal, vertical, 0f); or something along those lines – Latency Jun 1 '15 at 16:42
• This works!! Thank you so much for the simple fix, now I just need to work out how to change it from a boolean variable to like multiple variables or something (I will need 6 states) - Thanks again, sorry for my stupidity everyone. – R_Freeman27 Jun 1 '15 at 17:40

How about something like this:

public class TriggerMovement : MonoBehaviour
{
float speed;

enum eAxis
{
Normal = 0,
Switched,

MAX
}

Vector3[] horizontalAxes = new Vector3[(int)eAxis.MAX];
Vector3[] verticalAxes = new Vector3[(int)eAxis.MAX];

eAxis curAxis = eAxis.Normal;
void Start()
{
//Setup all axes you want to use here ...
horizontalAxes[0] = new Vector3(1f, 0f, 0f);
horizontalAxes[1] = new Vector3(0f, 0f, 1f);

verticalAxes[0] = new Vector3(0f, 1f, 0f);
verticalAxes[1] = new Vector3(1f, 0f, 0f);
}

void doMovement(Rigidbody rb)
{
//Get Input
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");

//Set input on appropriate axes
Vector3 horizontalMovement = horizontalAxes[(int)curAxis] * moveHorizontal;
Vector3 verticalMovement = verticalAxes[(int)curAxis] * moveVertical;

//Get total movement
Vector3 movement = horizontalMovement + verticalMovement;

//Scale by speed