- Home /
Using Trigger Keys on Xbox Controller To Zoom
I've looked just about everywhere and haven't been able to find a solution so I figured I'd ask the knowledgeable masses.
I'm trying to set up my Right Trigger on my Xbox360 controller to zoom in to a certain point on a map when pressed 1 time. If pressed a second time, the map should go back to the overhead view it started at.
I've run into 2 problems: Problem 1: I have the zoom working but it keeps zooming in or out when pressed multiple times by any of the controller buttons I get to work.
Problem 2: I can't seem to figure out what the number for the Left and Right Triggers are for the Xbox Controller.
I'm currently debugging my code by using this and checking the console:
if (Input.GetButtonDown("Zoom"))
{
Debug.Log("Trigger is pressed");
}
And my input button is set up like this:
Any suggestions?
Answer by ytwithlove · Jul 19, 2014 at 02:03 AM
Figured it out! Got an assist from a friend with my code but it looks like I was on the right track. Needed to create a bool variable then check against it so I could toggle the map. Ended up using a different button to get it to work but at least it works now. ^_^
Here's the code I was able to get to work:
//Variable
bool isZoomed = false;
Update()
{
if(Input.GetButtonDown("360_RightBumper"))
{
if (isZoomed) {
camera.orthographicSize = 44;
isZoomed = false;
}
else
{
camera.orthographicSize = 14;
isZoomed = true;
}
}
Answer by Chris_Dlala · Jul 15, 2014 at 08:33 AM
Hi, a while back I used Unify Community's page on Xbox360 controllers to get the mappings. They include a copy of InputManager.asset with all the entries for the Xbox controller. As for problem one, it sounds like that's what you wanted? I can only suggest storing the state of the zoom and checking against the state when the input is pressed. I hope that helps =)
I got pretty far using that but I can't seem to figure out what the triggers are. That probably sounds really weird so I'll explain.
I have the axis set up as the 3rd axis like the picture shows on the Unify site and what I have on my screen shot. I'm not sure what to put for the positive button - I know it mentions the triggers being 0 and 1 but I don't understand what that means.
Do I need to place LT as 0 and RT as 1?
I hope that makes sense and doesn't sound confusing.
You use Input.GetAxis("Zoom");
- if the result is 1 then the right trigger is pressed. If it's -1 then the left trigger is pressed.
Unfortunately using Input.GetAxis("Zoom"); didn't get any response from either trigger. And I still wasn't able to get the controller to work using the Unify example.
I'll keep picking at it and see what I can come up with.
I kept messing with the code and was able to map something to the triggers but the $$anonymous$$imap keeps zoo$$anonymous$$g too far out and won't switch back.
Here's the code I came up with:
if(Input.GetAxis("360_Triggers") >=0.001 )
{
camera.orthographic = true;
camera.orthographicSize += 40;
}
else
{
camera.orthographic = true;
camera.orthographicSize -=40;
}
Any suggestions to stop the consistent zoo$$anonymous$$g?
Your answer
![](https://koobas.hobune.stream/wayback/20220613154104im_/https://answers.unity.com/themes/thub/images/avi.jpg)