- Home /
Xbox 360 Controller (on Mac): Trigger initialises at "0" at game startup, but trigger itself is at position "-1", how can I get the correct value at startup?
How do I reconcile the fact that on Mac, the right trigger of an Xbox 360 controller returns a value of "0" when the game first begins, but the trigger axis itself is not being pressed and should initialise with a value of "-1".
Currently, I have to press the button once, then release it, then it gives me the proper -1 value. But when the game first starts, it's giving me the wrong value.
I want my character to jetpack around, and I'm trying to use the right trigger to return a value from 0 to 1.
I do a Math.Lerp to get the right trigger (on Mac this is called Axis 6) to turn the -1 to +1 range to a 0 to 1 range.
It all works great, except that when I start the game, my character immediately starts using their jetpack, because the controller says that the triggers are at position "0", when actually, they're at position "-1", because they're not being pressed.
Once I press the triggers, they reset properly, and give values -1. I just don't know how to force the controller to give a proper -1 reading at game startup! Any ideas?
Murray
Ahhh, after several hours of bashing my head against this problem, I think that posting it here helped me figure out a solution!
I just created a variable called ReadyToThrust = false.
The jetpacking controls do not start updating until this is true.
I set it to true only...
if (Axis 6 > -0.9) && (Axis 6 < -0.2).
That prevents "0" from triggering the jetpack updates. The player needs to press the trigger a little before ReadyToThrust is set to true, and then they can start jetpacking around as per usual!
Done!
Answer by mcteapot · Aug 26, 2013 at 04:48 AM
I ran into the same issue, in addition I needed to normalize the numbers between 0-1.
Here is the code I used to fix it, hope someone finds this useful.
float macReadTrigger () {
float adjustedAxis = 1.0f;
timeAxis = Input.GetAxisRaw("Trigger");
if((timeAxis > -0.9f && timeAxis < -0.0001f) && readyToShiftTrigger == false) {
readyToShiftTrigger = true;
}
if(readyToShiftTrigger) {
//Debug.Log("TIME SHIT: " + timeAxis);
if(timeAxis == -1) {
adjustedAxis = 0;
} else if(timeAxis > -1 && timeAxis < 0) {
adjustedAxis = (timeAxis * -1.0f) * 0.5f;
} else if(timeAxis == 0) {
adjustedAxis = 0.5f;
} else if(timeAxis > 0 && timeAxis < 1) {
adjustedAxis = (timeAxis + 1.0f) * 0.5f;
} else if(timeAxis == 1) {
adjustedAxis = 1;
}
}
return adjustedAxis;
}
Hi, the 5 IF statements can be replaced with: adjustedAxis = (timeAxis + 1) * 0.5;
Your answer
![](https://koobas.hobune.stream/wayback/20220613100547im_/https://answers.unity.com/themes/thub/images/avi.jpg)