This part of the tutorial will cover using the triggers on the game pads. The triggers give a value between 0 and 1 indicating how far the trigger is pressed, 0 being not pressed and 1 being fully pressed. There are two common ways we use triggers, using them as a button like shooting a gun and using them as a trigger were you use the value between 0 and 1 to correspond to an action such as a gas pedal of a car. The first step were going to do is to distinguish between our left and right triggers by creating an enum. For simplicity reasons I created this enum inside the Input file directly above the input class.
Next I created a const variable to distinguish the threshold to pass in order for the trigger to act as a button. You can change this value or even remove it entirely and have it as a parameter in your function, but I found that I always just used one number in all cases so it made the most sense to declare a constant.
Next were going to create the two functions were going to use for our triggers. Trigger will just return the value of that trigger and Trigger Threshold will return if we just passed the threshold or not.
Getting the Trigger is basic just go to our game pad state and return the right or left trigger. The Trigger Threshold is slightly more complicated but its just like with buttons checking if the previous state was off and the current state was on, if we check if the previous states value is less then the threshold and our current states value is greater then the threshold then it will return the correct value.
Now to use these in our other classes we can do just like we did with our buttons. Again common reasons to use the trigger are for things like the gas and brake for a car which you would use the Trigger and calculate your acceleration or braking. Or if you wanted to shoot a gun you would use the trigger threshold and if it is true you would shoot a bullet, or if its an automatic gun keep shooting.
Next time I will cover using thumbsticks which will be the last of the controller functions but there are some extra things that come in handy that I will add. Anything you would like to know about input let me know in the comments.