Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to distinguish input from different controllers?

Discussion in 'General Discussion' started by MaxPicAxe, Oct 27, 2018.

  1. MaxPicAxe

    MaxPicAxe

    Joined:
    Oct 27, 2018
    Posts:
    1
    Input.GetAxisRaw("Horizontal") will return the value of that axis. That axis is for either "all joysticks", "joystick 1", "joystick 2" etc (as specified in the Input Manager).

    But, how do I set to "all joysticks" and then, in the code, get each value for each joystick?

    I could add a "Horizontal1", "Horizontal2", "Horizontal3", etc. and for each set it to "joystick 1", "joystick 2", "joystick3". But the problem with this is... I have to create 16 of them if I want to support 16 controllers.... and also I am then limited to 16 controllers.

    I want unlimited controllers to be able to connect to the game, how do I do this? If I have to create 16 separate axis, that is ridiculous.

    P.S A lot of people seem to be creating there own "Input Manager", and that is what I would like to do, but can't figure out how.
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    Kiwasi likes this.
  3. BoogieD

    BoogieD

    Joined:
    Jun 8, 2016
    Posts:
    236
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    Yes, that's one of the problems, but it's not the worst problem. The worst problem is that most controllers have more than one axis and there is no consistency in the way they are numbered (eg axis one may be the d-pad for one controller but an analog stick on a different one). This exact problem applies to the buttons too.

    Unity may point you towards the Input Manager to define the controls for your game but the truth of the matter is it's completely worthless for any situation where you can't guarantee that the user will always have a controller with a very specific layout.

    Unity is working on a solution in the form of a completely new Input API, but until that's been released your only options are to either create your own framework for handling input (it's way easier than it sounds), or purchase one made by a third party like Rewired.

    For basic information on how to create your own framework, check the link below.

    http://luminaryapps.com/blog/configurable-input/
     
    Last edited: Oct 27, 2018
    Antypodish likes this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    Yep definitely I preference and suggest, to create own input system, with mapping IO.
    If done correctly, you can map easily for example forward movement to axis, keys, mouse, or other inputs.
    That way you can load your inputs configuration even from text file.

    Keeping inputs in one place. Preferably in same class.
    Don't call Input somewhere inside your game, as these become scattered and harder to maintain.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I use something very similar to this for my own configurable input systems. It works well on small games. But it still does feel very archaic. It doesn't for example let you automatically know which inputs are coming from which controller. Which means that if anyone plugs in a new device, you still have to go through the set up process.

    Highly recommend the asset store for solutions. Rewired is popular.
     
  7. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    SteamVR is on the right track with their input abstraction. You define actions then you can bind these to default bindings and player can override those. A action can be Boolean, single, Vector2 and even skeleton (gesture based).

    Unity should look at how they did it, though it needs some more work. Because with great abstraction comes great responsibility. For example I miss a binding conflict API and a way of getting the binding as a text so I can present in Tutorial and UI.