- Home /
Handling Controller disconnection? (reassignment, clunkyness, etc.)
Hey everybody!
(I'm going to be asking a general design question here, no specific code to debug or anything, but feel free to reply with specific code examples).
Is there a better way to assign controllers to players than the "whoever presses A first" method?
It seems extremely popular and kind of clunky / flawed.
Is there at least a better way to handle this if a controller disconnects during a game (such as remembering a MAC address or something)? I've had too many times playing games where one controller will disconnect and then the game either won't that controller reconnect at all, or it requires everyone to reassign their controllers.
I'm not necessarily looking for a built-in solution, I'm willing to build one. I'm just wondering if anyone has experience with a different solution, either by building it in their game, or seeing it in another game.
Answer by Tobychappell · Jun 12, 2018 at 10:37 PM
Using XInput you can search for a controller with an enum, rather than trusting the human to say they are player X when their controller has an LED saying they are player Y.
This way instead of letting the players dictate which controller to use for which in-game player object, you create the 4(?) controller instances and with some code you'll know the contoller index of the 2 players wether they are Player 1 and 2 or 2 and 4 or 1 and 3 etc..
I find this is better as with xbox 360 controllers they have that led showing them which number they are and it gets confusing if they are assigned to a different player.
As for Disconnections and reconnections XInput lets you test the connection... IsConnected() so you can quickly fallback to keyboard input. I'd suggest some sort of inteface that a keyboard listener and a controller listener implement so the overall input listener can use its own logic and switch between them if one is disconnected... OR take in both inputs and do the action if either listener detect the input.
I've attached XInput and my implementation of an XboxControlelr class.
Your answer
Follow this Question
Related Questions
how can i add a second player to this script? 0 Answers
UNET - Players Spawn With Misplaced Authority 1 Answer
my ball sometimes jumps higher or sometimes not 2 Answers
Error in the script 0 Answers