Building Block Heroes - Dealing with Controller Support for Multiplayer
I'm currently in the polishing stage of Building Block Heroes, and just a few weeks out from release. Since I've spent the last couple of weeks talking about the game itself, I figured I'd switch gears a bit and talk about some of the challenges I ran into during this crucial, final stage of development while making sure controller support worked.
I knew going into the development of Building Block Heroes that I wanted to encourage people to play with friends in local multiplayer, while still making it fun in singleplayer. This meant that I had to make it easy and convenient for players to be able to include their friends when they played the game. To facilitate this, I deliberately designed the game such that it would be possible for a second player to jump in or out at any time - think old-school arcade games with their "Here Comes a New Challenger!" notifications.
I originally envisioned three control schemes - the keyboard, and up to two controllers. This meant that multiplayer was only possible if there was a controller present. In today's PC gaming landscape, this isn't too much of a deal since most gamers seem to have a controller of some sort. However, as I was designing the default key mapping for the keyboard controls, I realized two things:
- The default layout assumes the player using the keyboard wants to use both hands.
- Forcing people to own/bring a controller for multiplayer isn't particularly conducive to casual gaming or gaming on the go with a laptop.
To mitigate this, I designed a second control scheme for the keyboard which makes use of the number pad. This allows a second player on the same keyboard, while providing an alternate one-handed control scheme for people who enjoy gaming with a drink in their hand or something.
What does this have to do with controller support? Because having a second control scheme for the keyboard dictated how I decided to handle the issue of controller disconnection for the second player. Handling it for player one was simple - just revert to the keyboard (or keyboard 2 if player two is using the keyboard already) if you disconnect player one's controller. Player two, however, required a lot more thought.
Out of curiosity one day I decided to see what would happen if I decided to arbitrarily disconnect the controller while selecting characters. To my horror, absolutely nothing happened - the character selection screen became unresponsive, with no way to back out or otherwise recover from the screen other than reconnecting the controller. "Okay," I thought, "I suppose the user can recover from it if he or she reconnects the controller." But then I thought, "What if the user doesn't? What if the person using the controller OWNS the controller and decides to pack up and go home?"
I suspect prevention of permanent unresponsive states is why arcade fighting games have a timer on the character selection screen. However, I didn't feel like forcing the remaining player to wait for 30 seconds or whatever to get back to the game if the other player takes his or her controller and goes away. Originally, I simply made the second player disappear and had the game revert to singleplayer mode when the controller was disconnected. When I added the second keyboard layout, unfortunately, I then had to consider the possibility that the second player might have disconnected the controller without actually wanting to stop playing.
Most games will offer the user a chance to confirm any action that will change the status quo of the game ie. saving or loading, or returning to the main menu. I figured I could use the same approach when determining whether or not to nuke player two when his or her controller is disconnected. When player two's controller is disconnected, the game brings up a popup asking if player two wants to leave. If the Yes button is pressed, the original solution of simply removing player two takes effect. If the No Button is pressed, then the control of player two reverts to whichever keyboard control scheme is currently unused.
Hop On, Hop Off
The issue of what to do when a controller is disconnected becomes more pronounced during actual gameplay. My original solution was simple - add a second player when the controller is connected, and remove it when the controller is disconnected. However, adding the Keyboard 2 control scheme again scuttles this solution, since it doesn't take into account the possibility of the controller being disconnected even if player two wishes to keep playing nor does it address the issue of which character to assign to player two.
To handle controller disconnects and reconnects during gameplay, I added an event handler that causes the same confirmation popups as before to appear asynchronously. That is, when a controller is plugged in at anytime during a singleplayer session, the game immediately pauses and the user is asked whether or not to add a second player. If Yes is selected, then the new controller is assigned to player two and the game returns to the player select screen. Otherwise, the controller simply becomes a new control scheme option in the Settings screen.
If two players are active and the controller for player two is disconnected at any point during gameplay, the same solution as the player select screen applies - choosing not to remove the second player reverts player two's control scheme to the unused keyboard option.
The last thing to consider with regard to having a second player jump in and out of the game actually had nothing to do with the controller support. I needed to provide a mechanism for enabling or disabling player two without having to rely on the controller connection event, in case players wanted to jump in using the keyboard. For this option, I simply created a "None" control scheme which player two is set to in singleplayer. Setting it to anything else prompts a confirmation popup asking the user whether or not to add a second player. Selecting Yes brings the game to the player select screen with player two's control scheme set to whatever is selected, while selecting No reverts the control scheme of player two to "None".
This article might not have been as fun to read as the ones talking about the game's areas, but I figured others who are at the same stage of development I am might find some use in reading about some of the design decisions I made when considering controller support. The process I went through can essentially be distilled into a couple of key questions:
- "How does the player decide to use a controller?"
- "How easy is it for a player to include a friend in their gaming session?"
- "How does the game add or remove a second player?"
- "What happens when you plug in the controller without warning on a certain screen?"
- "What happens when you unplug the controller without warning on a certain screen?"
I hope this helps others consider how to handle controller support and/or multiplayer in their own games! Feel free to follow me on social media if you enjoyed the read:
The Steam store page is also up, so feel free to check it out and wishlist the game if you find it interesting:
Thanks for reading!