playMaker

Author Topic: Solution for the XBOX 360/One Controller Trigger Input  (Read 33229 times)

Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Solution for the XBOX 360/One Controller Trigger Input
« on: August 21, 2015, 12:10:45 AM »
I've been struggling with this logic problem for 17 hours now in total. Finally got to solve it after intensive research.

When I needed this community to help me, it did it in a blink, time to give back some love : )

So, if you're using playMaker, and the XBOX 360/One Controller is the main input device for your game, and you're wondering why you can't get the Triggers to work, this is for you.

Microsoft made the Triggers to be sensible, therefore, they're Axis, not Buttons, in order to allow acceleration.

The problem: Even though you can get the Axis, how do you solve the acceleration? Why it starts in a already fired state?

The solution: The Axis range are -1 to 1. So why? Here lies the problem - The triggers are parked at 0 by default. From here, you can work your way to the solution, the images should be enough for a clear explanation of the logic. Notes included.







Special Thanks
Alex Chouls - For confirming what I was suspicious about the loop problem - http://hutonggames.com/playmakerforum/index.php?topic=6511.msg31804#msg31804
slog - for pointing out the problem of the 0 start state - http://answers.unity3d.com/questions/434129/mac-xbox-controller-detect-trigger-input.html

Other topics with the same problem
http://hutonggames.com/playmakerforum/index.php?topic=10971.0
http://hutonggames.com/playmakerforum/index.php?topic=10519.0
http://hutonggames.com/playmakerforum/index.php?topic=10354.0
« Last Edit: August 21, 2015, 04:28:56 AM by Cristiano Vitorino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #1 on: August 21, 2015, 02:53:34 AM »
hi,
thx for the tip, but the pictures can't be seen :)
can you upload them somewhere (not in your dropbox) and reconnect them?

Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #2 on: August 21, 2015, 04:30:08 AM »
hi,
thx for the tip, but the pictures can't be seen :)
can you upload them somewhere (not in your dropbox) and reconnect them?

Thank you for the heads up. I forgot that OS X makes TIFFs by default, my bad. The PNGs from imgur should be working now.
« Last Edit: August 21, 2015, 04:31:58 AM by Cristiano Vitorino »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #3 on: September 12, 2015, 06:07:14 PM »
So in other words, to make the trigger buttons to work. 0 on the trigger axis means its inactive, but for example to fire a weapon tell playmaker to detect 1 on the axis that the trigger is on, that should allow you to fire your weapon. untill you let go of the trigger and go back to 0 on the axis, and that will stop that fore action.

Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #4 on: September 13, 2015, 03:35:45 AM »
So in other words, to make the trigger buttons to work. 0 on the trigger axis means its inactive, but for example to fire a weapon tell playmaker to detect 1 on the axis that the trigger is on, that should allow you to fire your weapon. untill you let go of the trigger and go back to 0 on the axis, and that will stop that fore action.

Almost. It never goes to 0 again. On the moment you start pressing the trigger, it will become the range -1 to 1. Just like a car's accelerator pedal.

As you press for the first time, and keep pressing further, it will start the linear progression of the axis, -1, -0.9, -0.8... until it reaches 1.

In your example, once you release the trigger after shooting your weapon, the trigger will decrease its axis from 1 to 0.9, 0.8... going through 0, until you fully release the trigger and it rests at -1.

You can link an action to any of these values if you want, for example, so the weapon only shoots a bit late but not so late, let's say, at 0.3. Or implement an acceleration action, like stretching a bow string to shoot an arrow for example, and depending of the stretching strength, a different damage is applied.

It's a very odd behavior, it should start at the range, but it starts at 0 instead, to never go to 0 again once pressed for the first time, unless you quit Unity or the Game.

You can use the Controller Tester asset from the asset store to observe this behavior, it's free.

If you think this is a bit complicated, wait until you have to work with the Steam Controller, which has it's triggers working as an axis and buttons at the SAME TIME. I hope the behavior is separated, and not hardcoded into a single bahavior.

My guess is that it will have a "click" virtual (or maybe physical) button at the end of each range, working as a real button, to separate itself from the accelerating range behavior. If my guess is somewhat correct, then it will not be so complicated at all.

« Last Edit: September 13, 2015, 03:50:11 AM by Cristiano Vitorino »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #5 on: September 13, 2015, 10:18:27 AM »
So the triggers starts at 0, but when pressed it no longer will stop at 0 but actually start from -1 and go to 1, then when the trigger is let go; it goes down back to -1.

Now for my game i think this will be easy. All i have to do is anything greater than, lets say 0.1 fire weapon, then anything less than 0.1 stop firing. Is this correct?

Reason im asking becuase i beem trying to make the triggers work as button for a long time. Now with your post i think i can finally use the triggers as buttons.


Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #6 on: September 14, 2015, 02:38:42 AM »
So the triggers starts at 0, but when pressed it no longer will stop at 0 but actually start from -1 and go to 1, then when the trigger is let go; it goes down back to -1.

Now for my game i think this will be easy. All i have to do is anything greater than, lets say 0.1 fire weapon, then anything less than 0.1 stop firing. Is this correct?

Yup. That will do it. As long as you set up your actions for it to work like that. Any other value will work as well, as long as you set at least one value, it will work.

What will differ is the timing, close to -1 it will trigger really really fast, closer to 1 it will take a full push of the trigger to activate and will of course take longer.

In my post example, I'm listening to really anything, any value that is not 0. Because I didn't care for how much further the player would press the trigger, I just wanted it to act like a simple button.

Quote
Reason im asking becuase i beem trying to make the triggers work as button for a long time. Now with your post i think i can finally use the triggers as buttons.

Yeah, I feel ya, I wanted to achieve the same thing, and was able to, using the method I described in this post.
« Last Edit: September 14, 2015, 02:43:15 AM by Cristiano Vitorino »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #7 on: September 14, 2015, 02:45:57 PM »
Its kinda stupid on how they setup the controller. I kinda understand why they set the triggers to start at 0, but really they could have done something to make life easy by doing the following:

A. a option to toggle the triggers to be axis triggers, button triggers, or pressure sensitive triggers.

B. A option to actually start at -1 or 0. Heck a quick script that sets the triggers back to -1. When the level or game starts

C. Actually expain this in the Unity manual, because I dont think I really read anything about this.

Thanks a ton for this post. When i get home from work ill try this out and set 0.1 as the event to send, and see if it actually fires my weapon.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #8 on: September 14, 2015, 02:50:03 PM »
Built in support for Controllers in Unity is not good.

Just about everyone uses InControl or ReWired nowadays.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #9 on: September 14, 2015, 09:16:53 PM »

Thanks a ton for this post. When i get home from work ill try this out and set 0.1 as the event to send, and see if it actually fires my weapon.

No problem.

As Lane pointed out, you can get good assets from the Asset Store to deal with that.

You'll need something much more robust and standardized for a multi-platform release.

I personally don't need it yet, but I'll use InControl myself on the final release.

In case you decide to use an external asset, now, in the future or at any moment, one thing to consider when choosing the asset is paying attention on the support and stability of the addition of new controllers, or new controllers versions, like for example, the Steam Controller, that may or may not become popular. Or, as another example, the revised version of the XBOX One Controller, the XBOX Elite Wireless Controller that will release soon, that adds new buttons and new behaviors.
« Last Edit: September 14, 2015, 09:24:52 PM by Cristiano Vitorino »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #10 on: November 01, 2015, 11:33:33 PM »
Just to follow up. I am actually using  windows for my project. In windows the LT and RT are actually 0 to1. Unlike Mac its -1 to 1. So its eaier to program LT and RT in windows platform.

Also i manage to program the whole 360 controller for my project and everything works great.


Chris Vitorino

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #11 on: November 03, 2015, 11:11:26 AM »
Just to follow up. I am actually using  windows for my project. In windows the LT and RT are actually 0 to1. Unlike Mac its -1 to 1. So its eaier to program LT and RT in windows platform.

Also i manage to program the whole 360 controller for my project and everything works great.

Might be easier for you sure, but not to the player playing your game on OS X, which will have the triggers working differently.

Either simply keep separate builds for each platform or just use a third party asset to help dealing with that.

Quality porting is not so simple, but can be less problematic with the help from third party assets.
« Last Edit: November 03, 2015, 11:13:56 AM by Cristiano Vitorino »

meghapants

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Solution for the XBOX 360/One Controller Trigger Input
« Reply #12 on: July 11, 2016, 04:31:23 PM »
Thank you so much for this information. It was really helpful for setting up controller input in my project.

I'm building on Windows 10 with Unity 5.3.4, using an Xbox One controller.
The LT is bound to the 3rd axis, and the RT is bound to the 6th axis.

I struggled for quite a while to find that info, but finally found it here: https://community.unity.com/t5/Windows/Alert-Xbox-Controllers-Axis-mapping-changed-on-Win10-since-few/td-p/2569766

It was previously mentioned in this thread that using Windows it only ranges from 0 to 1. In my experience in this past week, on PC my triggers do range from a value of -1 to 1, just as Mac does.

Edit:
Windows Xbox One axis controller mapping:
Left Trigger - 3rd axis, ranges from -1 to 1.
Right Trigger - 6th axis, ranges from -1 to 1.
DPAD Horizontal - 7th axis, ranges from -1 to 1.
DPAD Vertical - 8th axis, ranges from -1 to 1.

-1 = resting state (not depressed)
1 = fully depressed
« Last Edit: July 14, 2016, 04:01:08 PM by meghapants »