I'm developing a game where it is possible for players (up to 4) to play simultaniously on one Computer/Console. Now I want the Input to be customizable, so that for example Player1 can choose the mouse as Input, Player2 the keyboard and Player3 an attached gamepad. The Input should be chooseable within the game, not only on startup.
What would be a good solution for this? Is it possible to use the InputManager for this task or have I to code this manually?
asked Mar 01 '10 at 12:41 PM
Thanks for your answers, perhaps one point was not clearly state by me. I don't want the players to choose the keys and buttons. I'm totally fine with defining them myself. But I want to have a defined set of "controllers" the players can choose of (eg. Keyboard1 -> WASD-Keys, Keyboard2 -> UP/DOWN/LEFT/RIGHT-Keys). My problem is connecting the defined Axis in the InputManager to my player-logic, where I have to descide if the current Input was meant for the player.
seems quite unelegant for me, but maybe thats the way to go
answered Mar 01 '10 at 02:52 PM
For the best flexibility, you would write your own Input wrapper, which you can configure. Then you'd have functions like this
,which wrap to Input manager functions using a key mapping, which maps your enums to KeyCodes. Then you could make a dialog where you handle Event.KeyDown type events, and assign the key codes to your mapping like this:
where m_Mapping is an array which maps from your enum to key codes. You can do something similar for axes.
answered Mar 01 '10 at 02:20 PM
jonas echterhoff ♦♦
there is not any built in feature for what you want. input manager just can customize those inputs that use GetAxis. so if you don't want to use that and want more than 2 players you need to code that yourself. simply when you want to use functions like GetButtonDown as argument send fire1p1 or fire1p3 for fire1 button of player 1 or 3. then in your game set those variables to what you want. input parameters are enums (simple numbers) that you can set to variables easily. you can create a manager object for controls that don't destroy in scene loads or just use static classes.
answered Mar 01 '10 at 02:21 PM
Since they have answered your question, let me give you a warning:
Most keyboards have a certain number of channels that they can recognize the state of at a time (8 is standard I hear). This means that no more than 8 buttons can be recognized at the same time, and if two buttons are on the same channel then they can not be read at the same time. Surely at some point youve played a game where left, up, and right worked, up+right worked but up+left did not, for example.
This is a hardware problem and there is no work around except to A) change control schemes B) change keyboards and pray (I have a number of Dell keyboards at my job's computer lab, and not all of them present with the same 'impossible pairs').
Note that some keyboards (like my Logitech G15) do not have/minimize this problem, because they have more channels (and thus less keys per channel).
answered Mar 01 '10 at 07:54 PM