- Home /
Removing Joystick Controls
I need to remove the default ability of receiving input from All Joysticks. As seen here: http://unity3d.com/support/documentation/Components/class-InputManager.html. I do not see an option similar to "Do not get motion from joysticks".
(Local Multiplayer) I'd like to have a control scheme for the keyboard, and another player use an xbox controller. However, I cannot remove player 1's ability to accept input from the controller.
Answer by Bravini · Oct 12, 2010 at 09:12 PM
a simple workaround would be to set the input scripts of player two as different inputs in the input manager, and don't configure joystick buttons or axis for it. An easy way to do this woud be to check the player to see if it's the player 2 and run the Walk2 instead of Walk.
So "Player 1" would have to have control of the keyboard and at least the joysticks of the first controller? I must be missing something. How would one do local multiplayer with two people and multiple "controllers" ($$anonymous$$B or Gamepad)?
At present, Player 1 is effected by Horiz and Verti Joystick movement of the first joystick. There wouldn't be a way to let player 2 plug in an xbox controller and play, because this would turn out to be joystick 1?
you`d have "horizontal" receiving input from joystick 1 on Joy Num setting on Input $$anonymous$$anager and "horizontal" (same name) receiving from Joy Num 2 or with "$$anonymous$$ey or $$anonymous$$ouse Button" on Type Setting. $$anonymous$$eyboard player will receive type "mouse or key button" so it ignores joystick inputs and joystick num 1 for example, while joystick player will have joystick num 2 and type "joystick axis" will ignore keyboard inputs.
same input names and scripts, with same name inputs on input manager but different type and joy num settings
I think, perhaps, my problem is laziness. I just applied their character controller and it accepts both.
After fiddling with this some more, I found the error was actually my mistake. I had (either by choice or default) the axes $$anonymous$$anager set to a larger than needed number (17). This added multiple Horizontal and Verticals.
Answer by idbrii · Sep 13, 2014 at 06:00 PM
The "Do not get motion from joysticks" option you're looking for is called "Joy Num".
To make your inputs work for multiple users, name your inputs after the player and always use numbered joysticks:
Axes: Create "P1_Horizontal" and select "Joystick 1" from the "Joy Num" dropdown.
Button: Create "P1_Jump" use "joystick 1 button 1".
Duplicate these for P2 and use "joystick 2"
In your player controller, add a public variable for the prefix ("P1_") and when calling GetAxes, prepend that prefix:
public string playerPrefix = "P1_";
...
{
bool is_jump = Input.GetButtonDown(playerPrefix + "Jump");
...
}
(If you're worried about the performance impact of string concatenation, define public variables for all of your inputs so you can pass them directly into GetButtonDown.)
When you add players to your scene, make sure you update their playerPrefix variable.
Following this pattern will allow you to keep your player controller code the same for two or more players. It should allow players to map different controls on each joystick or on the keyboard.
I got the joystick button names from here