Wednesday, 28 October 2015

Xbox Controllers

For my game I need to have different types of input so that two people can play the game at the same time. Obviously for a PC game I’m going to use the mouse and keyboard for one player, then for the other I’m going with an Xbox controller as it’s set up to work well in Unity. Setting the input axes for the controller has been quite simple and I think it’ll be easy to implement the controls into my final game.

To start with I wanted to add movement and look inputs. I discovered that the input manager is already configured to move the player with the left stick which saved me one job, however the right stick look controls needed to be implemented. I needed to create 2 new inputs called Controller look X/Y which were set to the 4th and 5th axis respectively. Upon playing the game, right stick caused the player to look around, although the Y axis was inverted so I simply checked the box the reverse it.
Two custom inputs

The other things I wanted to play around with was adding the ability to sprint, crouch and jump from the controller. I decided that the controls I wanted were: pressing in left stick (8 on diagram) would sprint, A (0) would jump and B (1) would crouch. Each of these were surprisingly easy as all I needed to do was add an OR condition to my if statements that check the corresponding action can be performed. This solution means that the player can move with either the keyboard and mouse or controller, so for my actual game I’ll need to add a check at the very start of the movement script to assign each player a single input type rather than the ability to use both.
Xbox controls map for reference in Unity

No comments:

Post a Comment