- Home /
Problem with 2 player mirroring input
I'm having a bit of an issue with 2 player input. It's my first time trying it, and I believe I got all the parts right, but something is still wrong.
I have 2 players on screen, all the movement controls are separate and work fine, but whenever I try to fire a player's lazer it fires it on both players.
I have checked and double checked everything, there are no naming mistakes going on, everything is separate. This is the script which handles the instantiate of the lazer, for player 1:
var p1Lazer : GameObject;
var p1LazerGun : GameObject;
function Update (){
if (Input.GetButtonDown("P1Lazer")){
var p1NewLazer : GameObject = Instantiate(p1Lazer, transform.position, transform.rotation);
p1NewLazer.transform.parent = p1LazerGun.transform;
}
}
And for player 2:
var p2Lazer : GameObject;
var p2LazerGun : GameObject;
function Update (){
if (Input.GetButtonDown("P2Lazer")){
var p2NewLazer : GameObject = Instantiate(p2Lazer, transform.position, transform.rotation);
p2NewLazer.transform.parent = p2LazerGun.transform;
}
}
And as for the input settings:
For some reason it's recognizing the joystick button input as the same for both controllers, while I have it listed on a separate controller in the input settings and I have given it different names. And I follow the same naming conventions for movement and that all works fine, but this does not. There is something wrong with that lazer instantiate script I believe (if I turn this script off on 1 player it does not fire the lazer on that player; it does on the other player). I have restarted Unity and my PC (so it's not my PC still configuring the joysticks), also plugged the joysticks in and out more than once. Scripts are added to the gameobjects properly. Do you maybe have any idea what's going on? It's a mystery to me.
If it helps I could upload the project folder.
Alright, so it's not the instantiate script, since I just did a check: if(Input.GetButtonDown("P1Lazer")){print("P1Lazer");} and also for P2Lazer, and I get a response from both. So it's something to do with recognizing input I guess.
So to check it up further I changed the joystick input on P2Lazer to spacebar. Then it works fine, it accurately differentiates between player 1's lazer en player 2's lazer and they don't fire both. But what's wrong with the joystick input then the way as it is entered in the image above?
Answer by Loius · Jan 21, 2013 at 08:42 PM
"Joystick Button X" means "Button #X on any joystick."
"Joystick Y Button X" means "Button #X on Joystick #Y"
The "Joystick Y" you've selected down below only applies to the axis inputs.
:science:
I figured the joy num setting on the bottom of the input listing would change that, but apparently you do have to write down the input setting as "joystick 2 button 4" etc. Damnit :p facepalm
Oh yes indeed. I imagine there have been so many facepalms on this topic that ... well... something drastic. Lots.