How to store two axis in one variable?

Hi guys.

So after many month I’m restarting and I’m a bit rusty… also I’m still a noob so it doesn’t help. XD

I whant to store two diferent input axis in one variable and can’t find how…

this is what I have:

roll = Input.GetAxis(“Roll1”);
roll = Input.GetAxis(“Roll2”);

problem is,this way, only “Roll2” work.

how do I put it to have both input work?

thanks mate.

found that and it work. is there a better way?

if (Input.GetAxis(“Roll1”) != 0)
{
roll = Input.GetAxis(“Roll1”);
}
else
{
roll = Input.GetAxis(“Roll2”);
}

Well firstly, why are you using Axis for what seems like an action? Are these to be mapped to two different joysticks?
If this is just horizontal and vertical, then just store it in a Vector2 like
someVector2 = new Vector2(Input.GetAxis("Roll1"), Input.GetAxis("Roll2"));

Then you can access the Roll1 value from someVector2.x, and Roll2 from someVector2.y at any point in your code.

Whatever you are doing, what you probably should not do, so tell us what roll1 and roll2 are:
roll = Mathf.max(Input.GetAxis(“Roll1”),Input.GetAxis(“Roll2”));

roll is the movement of the spaceship rolling on it self clock wise or counter clockwise. for this I whant to give 2 diferent set of controle for the same action. so if the left and is busy controlling some other movement you can still roll with your right hand and vice versa.

has I said I found a solution and it work, but is it the best I don’t know.
thanks y’all

I’m not sure how your proposed solution would solve that. If the Left “Roll1” is busy with some other movement, it’s going to have a non-zero value, no? And thus this code is actually going to use its values when that input is being used… So the only time Roll2 is being used now is when Roll1 isn’t being used, kind of defeating the purpose of what you’re suggesting.

What you could do instead is make a class to wrap your inputs in that you can then set parameters on, such as a bool saying the input is being consumed by another action right now so don’t utilize it, and then your code can choose to use a different input.

sory my bad… if your left hand is busy pressing an other key. you can still roll by pressing de designated key on the rig side of the keybord

but for your idea of making a class. wow. i’ll keep that in mind. thanks

just to be mor clair : “w” and “s” controle the pitch. “a” and “d” the yawn (I think it’s called that).

“[8]” and “[5]” strafe up and down. “[4]” and “[6]” strafe side way

so for roll I have etheir “q” or “[7]” to roll left and “e” or “[9]” to roll right

Q/E are designated roll1 and 7/9 are roll2

roll = 0;
roll += Input.GetAxis(“Roll1”);
roll += Input.GetAxis(“Roll2”));
roll = Mathf.Clamp(roll,-1,1);

Neat. I’ll try that tommorow. :smile: