Search Unity

[Released] cInput 2 - Unitys custom inputmanager got improved !

Discussion in 'Assets and Asset Store' started by Roidz99, Apr 4, 2012.

  1. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Every Axis in cInput is made up of cInput "keys" (actions) defined with SetKey. This way your players can change their controls at runtime. So yes, to use cInput, you first need to define a "Mouse Left" action and a "Mouse Right" action and then tell them to be used in an Axis with SetAxis.

    If you don't want your players to be able to customize the input, which in this case might make more sense for your usage, then you can continue to use Unity's Input class to handle mouse drags instead of doing it with cInput.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,607
    Hmm. OK, I see that I can get it to work by calling SetKey("Mouse Left", "Mouse Left") and so on for the other ones.

    It's starting to sink in now. I wondered why there wasn't any ChangeAxis method, but having tested now with a joystick plugged in, I think I finally get it:

    The "keys" set by SetKey and ChangeKey don't have to be actual keys; they can be anything, including a joystick axis moving in a particular direction.

    That's why an axis is defined by a pair of "keys" — it could actually be just a joystick moved two ways.

    But what do we do about inputs that can't be selected by the user? For example, I can't find any way to select a mouse movement, nor the Escape key, inside of ChangeKey. I can set them with SetKey, but once the user pokes at them, even experimentally, it seems that they can't get the original selections back without resetting all inputs to the default. Is that correct?

    Thanks,
    - Joe
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,607
    Sorry to be peppering the thread with questions... I wish the forum had a "thread search" feature, but I do search as well as I'm able before asking...

    I want to make a camera zoom axis that can be used with either the mouse wheel, or with whatever key or joystick inputs the user chooses (I'll default to left/right bracket). The problem is, keys or joystick inputs are continuous, and get processed every frame; mouse wheel movements are discrete. The net effect is, the zooming in/out is substantially faster when using the keys/joystick than when using the mouse wheel.

    I'd like to compensate for this by multiplying values coming in from the mouse wheel by, say, a factor of 10. But I don't see any way to tell when they're coming from the mouse wheel. Is this a "buy the pro version and hack the code" kind of thing, or is there a feature somewhere I've overlooked?
     
  4. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    You can pass additional arguments to SetKey to allow mouse axis inputs to be bound. They're not allowed by default.

    You're right that mouse inputs work differently than keyboard or gamepad inputs, so it's not usually a good idea to try to handle them the same way. You'll encounter similar problems if you try to handle looking around with a joystick and the mouse. It just won't work well.

    What I'd suggest is separate "actions" for mouse input so you will know where the input is coming from and can handle them separately/differently as appropriate.
     
  5. ryannelson

    ryannelson

    Joined:
    Feb 26, 2015
    Posts:
    4
    Hi all,

    Has anyone had success using the wireless Xbox 360 controller with cInput? It seems that the triggers do nothing. Unfortunately I don't have a wireless controller for testing (just USB), but a friend of mine who does is unable to play my prototype. Has anyone else run into this?

    Best,

    -Ryan
     
  6. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Hi Ryan,

    This is a known issue with Unity, and is not unique to cInput. The creator of the excellent InControl did a thorough write up of issues with the Xbox 360 controller in Unity:

    Details on the Xbox 360 Controller Bug in Unity

    The good news is that it seems Unity has finally taken steps to resolve the issue:
    It looks like 4.6.3p1 has been released (today!) but I don't see anything in the release notes about Xbox controllers, XInput, or controllers at all, so I'm not sure if it includes the remaining fix or not.

    Anyway, make sure you have the latest version 4.6.3+ and hopefully that should alleviate the problems with the Xbox 360 triggers.
     
  7. Navid

    Navid

    Joined:
    Sep 3, 2012
    Posts:
    39
    Hi,
    is it possible to add support for the zeemote controller ?
     
  8. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Hi Navid,

    I've never heard of the zeemote controller before, but there's a good chance that cInput already supports the zeemote controller.

    From what I can tell, it looks a lot like the Wii Nunchuck attachment, but it doesn't have any sort of motion controls? cInput should support the buttons and joystick, but if there are motion controls, cInput probably won't be able to read those.

    Basically, if Unity can see and work with the joystick and buttons of the controller, cInput should, too.
     
  9. Navid

    Navid

    Joined:
    Sep 3, 2012
    Posts:
    39
  10. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    As I said: If Unity doesn't natively support/recognize the controller, then neither will cInput.

    You could put in a bug report/feature request with Unity asking them to support the Zeemote.
     
  11. ryannelson

    ryannelson

    Joined:
    Feb 26, 2015
    Posts:
    4
    Thanks, I appreciate the response! I wasn't running 4.6.3, so hopefully that'll fix it. I gave InControl a try when I realized there was an issue, but it persisted--so it makes sense that it's a Unity bug. For whatever reason I groked cInput much easier than InControl. Keep up the great work, and thanks again!

    -Ryan
     
  12. Ennothan

    Ennothan

    Joined:
    Oct 17, 2013
    Posts:
    49
    Hi,
    Key Modifiers aren't working with mouse wheel for me.

    I declare the default key this way:
    Code (CSharp):
    1. cInput.SetKey("ZoomIn", Keys.MouseWheelUp, null, Keys.LeftControl);
    and just scrolling the wheel without holding control the next line returns true:
    Code (CSharp):
    1. cInput.GetKey("ZoomIn");
    I'm doing something wrong or it is really a bug?
     
  13. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    cInput doesn't support modifiers with analog inputs. It also doesn't support modifiers for a cInput Axis (something defined by cInput.SetAxis()).

    We didn't think it would make sense to have to hold down a key while pressing a joystick around, but it seems we may have overlooked the mouse. We'll revisit the idea of adding modifier support to mouse inputs.
     
    Last edited: Mar 6, 2015
  14. Ennothan

    Ennothan

    Joined:
    Oct 17, 2013
    Posts:
    49
    Alright, thank you Deozaan.
     
  15. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    195
    Just a quick message for the people who are using the cInput 4 UFPS bridge.

    We just submitted an update to make the bridge compatible with UFPS/Unity 5 so it should go live in a few days.

    If you can't wait that long send us an email.
     
  16. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    36
    Is there a workaround for setting modifiers at runtime and using them by themselves?
     
    Last edited: Mar 23, 2015
  17. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    This isn't officially supported by cInput. Something you could try is to use AddModifier() and RemoveModifier() throughout your code to sometimes use the key as a modifier and at other times allow it to be bound as a regular key. I haven't tried this, so there's no guarantee it will work.
     
  18. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Hi folks,

    An update to cInput has been submitted to the Asset Store. If you bought cInput from the Asset Store then the update should be live within a few (business) days. If you bought cInput from our website, then the update is available immediately.

    cInput changes:

    v2.8.1
    • Added cInput.anyKey and cInput.anyKeyDown properties.
    • Using PlayerPrefs is now optional with usePlayerPrefs bool (default is enabled).
     
  19. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    114
    I'm trying to figure out the best way to get a nice smooth input from my Xbox 360 triggers, and it's been a surprisingly difficult time.

    Here's how I'm doing it right now:
    Code (csharp):
    1.  
    2. cInput.SetKey("Attack", Keys.Xbox1TriggerRight);
    3. cInput.SetAxis("RightTrigger", "Attack");
    4. float lastTrigger;
    5. bool attacking;
    6.  
    7. void Update()
    8. {
    9. if (cInput.GetAxis("RightTrigger" > 0.5f && lastTrigger <= 0.5f) {
    10. attacking = true;
    11. }
    12. else {
    13. attacking = false;
    14. }
    15. lastTrigger = cInput.GetAxis("RightTrigger");
    16. }
    17. [/LIST]
    18.  
    Is there a "best practice" for getting input from the triggers? Because right now, this feels "off" when I try to press the button a bunch of times in rapid succession.
     
    Last edited: Mar 27, 2015
  20. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    I was wondering, in what way cInput is compatible with mobile? Only as in its ability to run on mobile and, let's say, handle a keyboard or pad attached to a mobile device? Or does it actually handle touch input? And if it does handle touch input then how (could not see anything in the manual)? I really don't want to use 2 input handling packages (one for touch and one for the rest) :).

    Sorry if this question was already asked. I searched and I could not get an answer so far.

    BTW, I use cInput extensively in my PC game right now and love it! So kudos! I just hope that when I switch to the mobile platform I can still use it as an exclusive input package.
     
  21. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Hi Doghelmer,

    I'm not sure what you're trying to do with your code. But perhaps you should try using GetAxisRaw so that the value is not affect by sensitivity/gravity adjustments.

    Hi cdevl,

    You are correct in your first assumption that cInput is compatible with mobile only in that it can handle a software or hardware keyboard/gamepad attached to a mobile device. It does not handle touchscreen or gyroscopic input. cInput is primarily for rebinding your controls at runtime, and it doesn't make sense to rebind touch or gyroscopic inputs.
     
  22. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    Do you have plans for a new Gui menu? I see it can be done, but its not an easy thing for most folks to jump into if we don't have the bandwith to learn the system. Would be especially awesome for all us VR folks... thanks!
     
    Last edited: Mar 28, 2015
  23. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Yes, we do have plans to include a "uGUI" (Unity 4.6+) menu. However, we like to have as broad backward compatibility as we can so that teams who are working with Unity 4.3 (for example) until their project is finished don't suddenly have a message from the Asset Store telling them they need to use Unity 4.6+ to download cInput. We actually still use Unity 3.5.7 to submit updates to the Asset Store for greatest compatibility.

    But now with Unity 5's release, we'll probably be bumping up the minimum supported version of Unity in the somewhat near future.
     
  24. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    114
    I guess to be more specific: All I'm trying to do is decrease the sensitivity of the left and right triggers, so that a tiny push won't register-- rather, the user will need to push the trigger down halfway in order for input to register as a "button down". I need something that works exactly like GetButtonDown for the left and right triggers, but is much less sensitive (when actually using GetButtonDown for the triggers, sensitivity is very high). I'm not sure how I'd best accomplish this, though I'm sure it's a really simple solution.
     
    Last edited: Mar 29, 2015
  25. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Try adjusting the deadzone settings for the triggers.
     
  26. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    114
    You mean something like this, right?:
    cInput.SetAxisDeadzone("RightTrigger", 0.19f);

    In that case, is there a proper way to do something like "GetKeyDown" for the axis? I know GetAxisRaw will give me a 1, 0 or -1 as long as I have the button down, but I just need to know about that one single frame where the input first registers, e.g. what GetButtonDown does for the other buttons.
     
  27. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Yes, I mean something like that.

    GetAxisRaw will give you the raw input value, unmodified by anything like sensitivity or gravity. For digital inputs (such as keyboard, or gamepad buttons) this is an int of either a 0 or a 1. For analog inputs such as joysticks or triggers, this is generally a float anywhere between -1 and 1 inclusive, but can sometimes go outside that range (such as for mouseball input).

    cInput supports binding analog inputs to digital actions (known in cInput as Keys) via SetKey. In fact, this is required in order to then bind them as a cInput axis. So just bind a trigger via SetKey and use GetKeyDown on it. Then, if it's down, check the value of GetAxis or GetAxisRaw as your needs require.

    Using your code example you included a few posts above, you'd do something like this:

    Code (csharp):
    1. if (cInput.GetKeyDown("Attack")) {
    2.     Debug.Log(cInput.GetAxisRaw("RightTrigger");
    3. }
     
  28. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    114
    Using "cInput.SetAxisDeadzone("RightTrigger", 0.4f);" gives me the following error:

    IndexOutOfRangeException: Array index is out of range.
    cInput._SetAxisDeadzone (Int32 hash, Single deadzone, System.String description)
    cInput.SetAxisDeadzone (System.String axisName, Single deadzone)
    PlayerControl.Awake () (at Assets/Scripts/PlayerControl.cs:374)

    It seems that I'm only able to set a dead zone when I set both a positive and negative input.

    If I do this:

    cInput.SetAxis("Triggers", "Attack", "Defend");
    cInput.SetAxisDeadzone("Triggers", 0.4f);
    (where "Defend is mapped to my left trigger)

    ...This has no effect on the sensitivity of cInput.GetKeyDown("Attack"). If I use the last piece of code that was posted in the quote, the output is always 0, since my deadzone is 0.4, and the GetKeyDown is typically triggered at around the 0.1 to 0.2 range.

    So, apologies for my continued inability to "get" this, but still no dice :)
     
    Last edited: Mar 29, 2015
  29. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    280
    How to input the android controller ??
    I want to use this with android ??
     
  30. Abel-Toy

    Abel-Toy

    Joined:
    Oct 7, 2012
    Posts:
    1
    Is there any way to have the joystick key texts more descriptive?

    Like for example, instead of displaying JoystickButton0 with an Xbox 360 controller, display "Button A" or something like that?

    Thanks!
     
  31. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Thanks for the bug report about getting an error when trying to set deadzone when only one input is defined for an axis. I've got the problem corrected and the fix will be available in the next release of cInput. (This problem also affected sensitivity and gravity.)

    I gave you bad advice on how to detect the "value on first pressed." I apologize for that. I forgot that the GetKeyDown doesn't take deadzone into effect, so it is as you described: GetKeyDown returns true when the axis value is about 0.1 or 0.2, but the GetAxis and GetAxisRaw ignores any value below the deadzone, so it returns 0.

    Here's an example of how you can get the value when it is first pressed down greater than the deadzone:

    Code (csharp):
    1. bool axisPressed = false; // this will be the flag to set on the first frame the axis is pressed
    2.  
    3. //somewhere in your Update or wherever you're checking for input:
    4. void Update() {
    5.    float triggerVal = GetAxisRaw("Triggers");
    6.    if (triggerVal > 0) {
    7.       if (!axisPressed) {
    8.          // this is the first frame the axis has been pressed
    9.          Debug.Log(triggerVal);
    10.          axisPressed = true;
    11.       }
    12.  
    13.       // do other stuff here you want to happen each frame the axis is still pressed
    14.      
    15.    } else {
    16.       axisPressed = false; // trigger is no longer being pressed above deadzone value
    17.    }
    18. }
     
  32. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    If you have a physical gamepad you're connecting to your Android device, cInput should be able to detect it and work with it, assuming Unity supports it. For any more specific assistance, I'm going to need more specific information from you.

    Yes. cInput doesn't handle this for you, but you can use a switch statement or something similar to display "Button A" when GetText returns "JoystickButton0" (for example) based on which gamepad you've detected as being used.
     
  33. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180

    Hi Deozaan,

    Thank you for your response. It helped me to understand the direction I need to move in. I don't actually completely agree with your statement though. Almost any touch control (maybe excluding multi-touch) can usually be translated to a mouse control pretty much one-to-one with some small exceptions. So, your mouse control support rebinding can very nicely translate to touch controls (again with some exceptions and assumptions). It would definitely be interesting to see that kind of implementation.
     
  34. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    280

    physical gamepad ??
    You mean a xbox 360 controller ??
    I mean a normal gui controller in android is this possible ??
     
  35. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    I mean a physical hardware gamepad, whether it's connected via bluetooth or USB OTG, or something similar.

    What do you mean by a "normal gui controller in android"? Do you mean that you will make some GUI touch screen controls using OnGUI or uGUI other Unity GUI asset to imitate a controller layout on screen? If that's what you mean, the answer is no, cInput doesn't support touchscreen or gyroscopic controls.

    If you're talking about something else, then you're going to need to be more specific. Can you please point me to an image or a video or a website of what you're talking about?
     
  36. AlbertStr

    AlbertStr

    Joined:
    Feb 12, 2014
    Posts:
    13
    Hi!

    Is it possible to define SetKey for more than two keys/buttons? I would like to accept input of any Xbox controller/keyboard plugged. I tried something like:

    Code (CSharp):
    1.  
    2. cInput.SetKey(InputButton.LEFT, Keys.A, Keys.Xbox1LStickLeft);
    3. cInput.SetKey(InputButton.LEFT, Keys.Xbox2LStickLeft, Keys.Xbox3LStickLeft);
    4. cInput.SetKey(InputButton.LEFT, Keys.Xbox4LStickLeft);
    5.  
    But only the first one is mapped.

    Thanks in advance!
     
  37. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Sorry, but this is not supported by cInput. Each cInput action ("Key") can only have 2 inputs assigned to it. To work around this, you could do something like:

    Code (csharp):
    1. cInput.SetKey("Left", Keys.A, Keys.LeftArrow);
    2. cInput.SetKey("GamepadLeft", Keys.Xbox1LStickLeft, Keys.Xbox2LStickLeft);
    3. cInput.SetKey("GamepadLeftAlt", Keys.Xbox3LStickLeft, Keys.Xbox4LStickLeft);
     
  38. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    cInput works awesomely for me but there's one more thing that would really help. Can there be a list of currently held down buttons? This would complement cInput.anykey and be especially useful for games that use numbers (i.e. for control groups). Instead of doing

    if(cInput.GetButtonDown("1")){
    ActivateGroup(1);
    }
    else if(cInput.GetButtonDown("2")){
    ActivateGroup(2);
    }
    ...
    else if(cInput.GetButtonDown("9")){
    ActivateGroup(9);
    }

    cInput users could simply do:
    if (cInput.anyKey)
    {
    foreach (string input in cInput.KeysDown)
    {
    int ControlGroup = -1;
    int.TryParse(input,ControlGroup);
    if (ControlGroup != -1)
    ActivateGroup(ControlGroup);
    }
    }
     
  39. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Here's, I think, a workable compromise. When you create a key, the SetKey() function returns a hash which you can use to quickly refer to that input in the future (instead of having to parse strings all the time). Use those hashes to store and iterate only the keys you're interested in instead of iterating every single key that is pressed in hopes that it matches 0-9. Something like this:

    Code (csharp):
    1. List<int> controlGroupKeys = new List<int>();
    2.  
    3. void Start() {
    4.     // create the keys and add them to the List at the same time
    5.     controlGroupKeys.Add(cInput.SetKey("1", Keys.Alpha1));
    6.     controlGroupKeys.Add(cInput.SetKey("2", Keys.Alpha2));
    7.     // ...
    8.     controlGroupKeys.Add(cInput.SetKey("9", Keys.Alpha9));
    9. }
    10.  
    11. void Update() {
    12.     if (cInput.anyKey) {
    13.         for (int i = 0; i < controlGroupKeys.Count; i++) {
    14.             if (cInput.GetKeyDown(controlGroupKeys[i])) {
    15.                 ActivateGroup(i);
    16.             }
    17.         }
    18.     }
    19. }
     
  40. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Awesome! Thanks a lot - that's really helpful.
     
  41. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I have a question about hashcode generation. Is it random or incremental? I'd like to send input accross the network and it'd be more efficient storing the hashcode in a byte if it's incremental. If I don't register more than 256 keys, will the hashcode ever overflow a byte?
     
  42. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    The hashcode is based on the string name of the cInput action. So if you do something like SetKey("Jump", Keys.Space); it will return "Jump".GetHashCode();
     
  43. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Oh, darn. Well, guess I'll just have 2.1 billion possible inputs :p.
     
  44. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    Hi folks,

    An update to cInput has been submitted to the Asset Store. If you bought cInput from the Asset Store then the update should be live within a few (business) days. If you bought cInput from our website, then the update is available immediately.

    cInput changes:

    v2.8.2
    • Fixed error when setting deadzone/gravity/sensitivity for axis with 1 input. (Thanks Doghelmer)
    • cInput fires an event when keys are changed via GUI or ResetInputs. (Thanks CaptainChristian)
    The OnKeyChanged event is particularly useful for when you've got your own custom GUI and you need to know when to update the text elements after some input changes.
     
  45. hodge_podge

    hodge_podge

    Joined:
    Feb 22, 2015
    Posts:
    30
    Is there any likelihood to see official Unity UI support anytime soon with the pro asset? I'm actually using the free version because I find there is more documentation on how to use the 4.6 UI with it.
     
  46. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    The Pro version and the "free" Dev version are exactly the same functionally speaking. But the Pro version comes with the source code. The Unity 4.6 UI is completely compatible with cInput 2.x, Pro or otherwise. The documentation you are finding should apply equally to cInput Pro as it does for cInput Dev Edition.
     
  47. hodge_podge

    hodge_podge

    Joined:
    Feb 22, 2015
    Posts:
    30
    I'm actually using an modified version of that old roidz Custom input manager 1.4 for my Unity Project, I understand cInput changed the code quite a bit. How exactly would I go about making my GUI work with the newer cInput 2.x?
     
    Last edited: Apr 7, 2015
  48. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
  49. hodge_podge

    hodge_podge

    Joined:
    Feb 22, 2015
    Posts:
    30
    This will help, thank you. I take it I will have to create a setup script with a public setkey function for the uGUI buttons, correct?
     
  50. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    652
    That sounds right, except you probably don't want one for SetKey, but ChangeKey instead.
     
unityunity