XBOX 360 Controller Trigger Button

I am trying to use a xbox controller for my fps.
I use the XBOX 360 Driver for Mac by Colin Monro

When i use the Joystick Test Program at:
http://www.rotorheadgame.com/unity/joytest.html

It says the Left/Right Triggers are 5th/6th Axis
NOT a ‘joystick button x’ (x being actual button number like 0 for fire)

I used the Input Manager to make another ‘Fire1’ Axis
Type: ‘Joystick Axis’
Axis: ‘Joystick 6th Axis’

Now first off since there is nothing i can put for button positive (because it only allows text like ‘joystick button 0’… cant enter ‘Joystick 6th Axis’ the GUI wont accept this) i am force to change my code from Input.GetButtonDown(“Fire1”) to Input.GetAxis(“Fire1”) > 0.0 to tell if the use press the fire button… The problem is that GetButtonDown only fire true in the FRAME that button was pressed in which great for a single fire thing (that is what i want) but for me to be able to use the trigger from the xbox 360 controller to fire a weapon (single shot for now) and since the ‘Button Positive’ wont take the value ‘Joystick 6th Axis’ i have to use GetAxis(“Fire”)
now this fires in every frame…

How can i only do my weapon fire code (Which instantiates a missle game object) for the frame the joystick button was pressed in (basically get the same functionally of the GetButtonDown but with a GetAxis so my weapon only fires once per trigger pull … not fire off 100+ missiles becuase i have the trigger held down and GetAxis(“Fire1”) > 0.0 will ALWAYS BE TRUE… Even on the way down of pulling the trigger and back up… WHEN the trigger is fully neutral is the ONLY time GetAxis(“Fire1”) will be less than or equal to 0)

So i need help in ‘tweaking’ the normal code used in the tutorials use GetAxis instead of GetButtonDown but all the features of GetButtonDown to ensure 1 shot per trigger pull or how do i make the Input Manager treat the trigger pull like a regular button fire…

Or any other info on how to use the XBOX 360 Right trigger to fire a weapon like the keyboard ‘Ctrl’ Key

The two axis only work with XInput.
With DirectInput and libraries like FreeJoy they are only recognized as buttons thus you get true from the first to the last moment they are pressed.

Thats microsofts error because they just wanted to enforce XInput against any intelligence (and against a few hundred games that don’t work right with them due to this not understandable decision)

You’ll have to compare the current input state to the one in the previous frame, which you will have to record:

private var oldTriggerHeld : boolean;

function Update() {
	var newTriggerHeld = GetAxis("Fire1") > 0.0;
	if (!oldTriggerHeld  newTriggerHeld)
		Fire();
	oldTriggerHeld = newTriggerHeld;
}

Can anyone help convert the above code into C? Really having trouble with this.

C as in ‘C’? Why do you need the code in C?

As in C#.

Just because my current script for the controls is in C# and I’m trying to adapt it to work with a 360 controller and this exact same problem has been bothering me.

I tried converting it to c# myself with what little knowledge I have of it and sort of failed. I got response from the triggers at least, but they fired the weapon once per frame once pressed.

[quote=“anon_48904847, post:6, topic: 394205, username:anon_48904847”]
As in C#.
[/quote]Ah, just a typo then I guess. (C and C# are different languages, but I guess you probably know that.)

Anyway, here’s what that code might look like in C# (not compiled or tested):

public class MyClass : MonoBehaviour
{
    bool oldTriggerHeld;
    
    void Update()
    {
        bool newTriggerHeld = Input.GetAxis("Fire1") > 0f;
        if (!oldTriggerHeld  newTriggerHeld) {
            Fire();
        }
        oldTriggerHeld = newTriggerHeld;
    }
}

Only just got around to implementing this, it works, thanks!

I was pretty close, just some minor differences but they made a big impact!