So I’ve seen people ask this type of question before but I don’t see an actual solution to this problem anywhere and am wondering if there is one. I saw one person mention that you could maybe list the triggers as actual joystick buttons instead of referring to them as 3rd axis, but I’m unclear on how to set that up in the actual input manager so I can use it. The 3rd axis method just doesn’t seem to work because pressing both triggers at the same time resets the entire axis to 0. I really have to be able to press both triggers at the same time. Thanks for any help or suggestions!
8 Answers
8I’ve discovered that the analog triggers actually do have their own separate axes. If you make a build of your game as a standalone, you can configure input axes at launch. The triggers give axis 8 and 9. The axis numbers are zero based there, and they are start at one in the input settings in the editor. If you could access controller axis 9 and 10 in the editor, you could get the trigger inputs separately from the start.
So axes 9 and 10 are the Xbox 360 controller’s trigger inputs as separate axes for the standard Windows driver. You just can’t access them without the user binding them; and only in a standalone build.
pretty frustrating.
I don’t know what you guys are doing wrong, but Axis 9 and 10 work perfectly for me. I was stuck on the 3rd axis problem for a bit. Unity version 3.5.6f4
Actually he’s right, 9 and 10 work. but you need to use them as you would any other axis.
What I mean is you need to store the input form axis 9 and 10 into a float and use that float as the conditional for the commands you a trying to do.
Here is an example script… lets assume you want to fire “shot1” when you press the right Trigger (axis 10) and fire shot 2 if you press the left trigger (axis 9) or fire both shots at the same time.
first set up you inputs in the input manager like this (leave blank any boxes i don’t give you the info for)
--------…
name : Fire1
Gravity : 0
Dead : 0.19
Sensitivity : 1
Type : Joystick Axis
Axis : 10th axis (Joysticks)
Joy Num : Get Motion from all Joysticks
--------------AND…
name : Fire2
Gravity : 0
Dead : 0.19
Sensitivity : 1
Type : Joystick Axis
Axis : 9th axis (Joysticks)
Joy Num : Get Motion from all Joysticks
----------------------OK NOW THE SCRIPT ITSELF…
using UnityEngine;
using System.Collections;
public class Guns : MonoBehaviour
{
public float fireRate1;
public float fireRate2;
public Transform shotSpawn1;
public Transform shotSpawn2;
public GameObject shot1;
public GameObject shot2;
private float leftTrigger;
private float rightTrigger;
private float nextFire1;
private float nextFire2;
void FixedUpdate ()
{
leftTrigger = Input.GetAxis ("Fire2");
rightTrigger = Input.GetAxis ("Fire1");
if (rightTrigger > 0.1f && Time.time > nextFire1)
{
nextFire1 = Time.time + (fireRate1 * Time.deltaTime);
Instantiate(shot1, shotSpawn1.position, shotSpawn1.rotation);
}
if (leftTrigger > 0.1f && Time.time > nextFire2)
{
nextFire2 = Time.time + (fireRate2 * Time.deltaTime);
Instantiate(shot2, shotSpawn2.position, shotSpawn2.rotation);
}
}
}
I hope this helps. I am pretty new to all this myself but I tested this and it works for me.
I found this thread on the forum that might be able to help. Actually, a general google search will probably put you on the right track.
Yeah I've seen that thread before and searched Google a ton and the general consensus is that it doesn't seem to be possible, which just seems odd because I've played a number of game where you can press both triggers together to shoot or whatever and they seem to work just fine. If I could just make Unity read them as separate buttons instead of being on an axis that would be better.
– wilco64256I do actually understand what you're saying, but it's wrong because if that was the only way for the triggers to be read then no game would allow them both to be used at the same time.
– wilco64256Yep. The issue is at a driver level, not hardware level. If you use the XInput API, you can poll the triggers on an individual basis, but in other, less deep drivers, they're treated as a linked axis. I've been trying to figure out exactly why microsoft would make this decision (it cuts out a lot of obvious potentials, as noted before - no way to tell that left and right are pulled at the same time), but I have no idea. Probably some awful sibling of the concept of "engineered obsolescence". I really hope the axis 9 and axis 10 thing work, but I'll have to test it.
– Bezzythanks ![]()
Axis 9/10 doesn’t seem to function properly with supporting more than one xbox controller.
In my experience, they crosstalk and you actually need to move BOTH left or right triggers (if you plug in two controllers) and it’s exact interaction seems to be very inconsistent.
Except triggers aren’t joysticks - they’re separate buttons by themselves. There are plenty of games out there where you can press both at the same time to shoot multiple weapons at the same time or do other simultaneous things. If they weren’t meant to be pressed at the same time then the controller should be physically designed so that they can’t be pressed at the same time. It has to be possible.
Just to prove a point- open up your joystick manager in windows and watch the "Z Axis" bar. When you press both triggers simultaneously, they 'jiggle' for a microsecond before returning to zero. This is because it's actually very difficult to press two buttons with different hands at exactly the same moment. Most games that implement this type of functionality capitalize on this to detect simultaneous input, but it's not foolproof.
– testureYeah I'm not trying to make people press both at the exact same time, I just need to allow for them to do so if they want to. Like a player holding a gun in each hand should be able to fire both at the same time.
– wilco64256Such apologetic logic is just annoying. They commingled the responsibilities of the triggers by binding them both to axis 3. Just another example of a Microsoft fail.
– nventimigliaI should have updated this some time ago, but at least I am now - somewhere along the way Unity was updated such that it now reads these two buttons separately with the left trigger reading as button 6 and the right trigger as button 7. It also reads both buttons pressed at the same time no problem.
I can't get this or the Axis 8/9 working at all on Unity 4 or 3.5.6 - is this still operating correctly for you in Unity 4? If so, could you post a screenshot of your inputmanager and/or your Input calls that are returning true?
– goodhustleI get axis 8 and 9 working...sometimes. It will often fail if I switch controllers, or the first time that I plug the controller in on a new computer. Re-running the executable or unplugging / replugging the controller seems to fix it, but if it's not dependable it's kind of a deal breaker. Looking into xinput now.
– thegreatzebadiah
@wilco64256 I agree with your point below but please don't post comments as answers. It makes it look like you're receiving more responses to your question and people will be less likely to give it a look. I suggest deleting your answer and adding a comment here with it's text instead.
– Chris-D