Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mapping Multiplayer Controls for Play on a Single PC


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Mia.   Members   -  Reputation: 494

Like
0Likes
Like

Posted 03 April 2014 - 07:06 PM

Hi, I'm currently programming player controls in a small RPG. Because the game also has a co-op mode, I want to make it so that both players can comfortably play on the same computer without getting in each other's way. My question is, how can I do this while ensuring that each configuration has the same advantages as the others? In other words, one mapping is not harder to use than another.

 

These are the default key configurations I came up with thus far:

 

AWDS   ARROW KEYS    NUMBERPAD               MOUSE

 

   w              /\                            8                    <point and click>
a    d       <       >                   4       6
   s               \/                            2     *(or 5)       *(hold the click to continue moving in that direction)

 

I am aware that many laptops lack a number pad and not everyone has access to a mouse.

 

How can I allow the player to also set his or her own key configuration if he or she is not comfortable with one of the default settings? Should I put it in the pause menu, where it can be changed during gameplay, or under "settings" in the main menu?



Sponsor:

#2 cardinal   Members   -  Reputation: 903

Like
1Likes
Like

Posted 04 April 2014 - 12:10 AM

Is controller support out of the question? Or are you looking specifically for keyboard only controls?

 

I would imagine if you support controllers, you would just plug another controller in and player 2 gets the same input as player 1 without having to share a keyboard.

 

 

For allowing players to specify their controls,  you would build a screen that lets each player map a physical key to a virtual button and do some sanity checking to ensure there aren't missing or duplicate mappings. The mapping could be as simple as an array that maps a physical key ID to a virtual key ID (you would have one mapping for each user or gamepad). When you process the physical inputs you would write to your input buffer, When you want to see if you want to perform a certain action mapped to  a virtual key, you would look at the physical key state mapped to the virtual input and act accordingly.



#3 Satharis   Members   -  Reputation: 1264

Like
1Likes
Like

Posted 04 April 2014 - 01:05 AM

How can I allow the player to also set his or her own key configuration if he or she is not comfortable with one of the default settings?

Not really any simple answer to this, most of this lands in the purview of an input system, usually you want to move from using raw keys to instead making "actions" or something, whatever you would probably label it as on the rebind menu, and have the game code translate a key press into that using a map or something.

For instance you could configure it so when the W key is pressed it translates that from a keypress into a "p1MoveUp" event, or something, you could use an enum or something for that if you want. Then just take it from there, either make an array of events and set their state or something if you want to use polling, or have an actual callback to tell the code player 1 is pressing the move up key.
 

Should I put it in the pause menu, where it can be changed during gameplay, or under "settings" in the main menu?

No brainer, they should be able to do both.

There's really not any design reason why it wouldn't be better that way. In fact most games should(and tend to fail at) give you the same options ingame to change as they do at the title screen.

Edited by Satharis, 04 April 2014 - 01:07 AM.


#4 Strewya   Members   -  Reputation: 1583

Like
1Likes
Like

Posted 04 April 2014 - 01:35 AM

You should also be wary of hardware limitations. Some keyboards can't have more than 2-4 keys pressed with them registering as individual keypresses. This has to do with the interface type of the keyboard (PS/2 or USB), the type of keyboard (mechanical vs membrane) and the build process (how the internal hardware registeres key presses).

Look into ghosting and key rollover for more info.

 

What you plan here is having 2 players on one keyboard. If we assume the minimal number of simultaneous key presses required is 2 (diagonal movement), then you'll reach the maximum number of registered key presses really fast (for people who have (2|3|4)-KRO keyboards), with the result of only one player moving, or both players moving in only one direction (and not diagonal which they wanted). I suggest you provide alternative input devices for extra players on the same computer, otherwise your game might be unplayable for some people.


Edited by Strewya, 04 April 2014 - 01:36 AM.

devstropo.blogspot.com - Random stuff about my gamedev hobby


#5 Mia.   Members   -  Reputation: 494

Like
0Likes
Like

Posted 04 April 2014 - 03:51 PM

Is controller support out of the question? Or are you looking specifically for keyboard only controls?

 

I would imagine if you support controllers, you would just plug another controller in and player 2 gets the same input as player 1 without having to share a keyboard.

 

 

For allowing players to specify their controls,  you would build a screen that lets each player map a physical key to a virtual button and do some sanity checking to ensure there aren't missing or duplicate mappings. The mapping could be as simple as an array that maps a physical key ID to a virtual key ID (you would have one mapping for each user or gamepad). When you process the physical inputs you would write to your input buffer, When you want to see if you want to perform a certain action mapped to  a virtual key, you would look at the physical key state mapped to the virtual input and act accordingly.

 

Thank you very much! Your post is very helpful. I hadn't thought about using a controller (I suppose it's a USB connection?). That's a good idea though. For the time being, I can only develop using the keyboard and the mouse because I do not currently own a controller to test the controls with.



#6 Mia.   Members   -  Reputation: 494

Like
0Likes
Like

Posted 04 April 2014 - 04:02 PM

 

How can I allow the player to also set his or her own key configuration if he or she is not comfortable with one of the default settings?

Not really any simple answer to this, most of this lands in the purview of an input system, usually you want to move from using raw keys to instead making "actions" or something, whatever you would probably label it as on the rebind menu, and have the game code translate a key press into that using a map or something.

For instance you could configure it so when the W key is pressed it translates that from a keypress into a "p1MoveUp" event, or something, you could use an enum or something for that if you want. Then just take it from there, either make an array of events and set their state or something if you want to use polling, or have an actual callback to tell the code player 1 is pressing the move up key.
 

 

 

I had been using the raw key input, but I understand now that enumerations would be a lot more useful and versatile in this case. Thank you.



#7 Mia.   Members   -  Reputation: 494

Like
0Likes
Like

Posted 04 April 2014 - 04:18 PM

You should also be wary of hardware limitations. Some keyboards can't have more than 2-4 keys pressed with them registering as individual keypresses. This has to do with the interface type of the keyboard (PS/2 or USB), the type of keyboard (mechanical vs membrane) and the build process (how the internal hardware registeres key presses).

Look into ghosting and key rollover for more info.

 

What you plan here is having 2 players on one keyboard. If we assume the minimal number of simultaneous key presses required is 2 (diagonal movement), then you'll reach the maximum number of registered key presses really fast (for people who have (2|3|4)-KRO keyboards), with the result of only one player moving, or both players moving in only one direction (and not diagonal which they wanted). I suggest you provide alternative input devices for extra players on the same computer, otherwise your game might be unplayable for some people.

 

I wasn't aware of that limitation. Thanks for bringing it to my attention! The alternate input device I provided was the mouse, but I also noted that this could be a problem for laptop users who would normally use a touch pad rather than a USB mouse. Cardinal suggested that I consider game controller support, and I think that might just be the thing to alleviate that problem.

 

Perhaps I could include support for all three mediums--keyboard, mouse, and game controller--to make the game accessible to as many players as possible. I would have to buy a controller first, however, to develop such a thing. Thanks for the response!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS