x


Multiple Players on one Computer/Console

Hello,

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?

regards

more ▼

asked Mar 01 '10 at 12:41 PM

knoggly gravatar image

knoggly
157 7 8 12

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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.

something like

if(playerNum==1)
{
  value=Input.GetAxis("Player1 left/right");
}
else if(playerNum==2)
{
  value=Input.GetAxis("Player2 left/right");
}

seems quite unelegant for me, but maybe thats the way to go

cheers knoggly

more ▼

answered Mar 01 '10 at 02:52 PM

knoggly gravatar image

knoggly
157 7 8 12

(comments are locked)
10|3000 characters needed characters left

For the best flexibility, you would write your own Input wrapper, which you can configure. Then you'd have functions like this

bool GetKeyDown(KeyEnum key)
{
    return Input.GetKeyDown(m_Mapping[(int)key]);
}

,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:

void AssignKeyFromEvent(KeyEnum key)
{
    if (Event.current.type == EventType.KeyDown)
        m_Mapping[(int)key] = Event.current.keyCode;
}

where m_Mapping is an array which maps from your enum to key codes. You can do something similar for axes.

more ▼

answered Mar 01 '10 at 02:20 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 01 '10 at 02:21 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered Mar 01 '10 at 07:54 PM

Kethis Celebes gravatar image

Kethis Celebes
149 8 9 18

Thanks for your hint

Mar 04 '10 at 05:25 PM knoggly
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x984
x954
x195
x50
x42

asked: Mar 01 '10 at 12:41 PM

Seen: 2228 times

Last Updated: Mar 01 '10 at 12:41 PM