- Home /
Question by
Pendragon420 · Feb 24, 2016 at 07:12 PM ·
inputjoysticknumberinverted
is it normal for my joystick number to swap in a multiplayer game? player 1 is player 2 and vice versa
i cant seem to find the issue, when i wrote the code and was testing it, it was working perfectly, and then i built the game and it swapped the controllers over, and the triggers stopped working, i fixed the triggers by changing it to the 3rd axis, but the inputs still seem to be swapped.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Player_Manager : MonoBehaviour {
//ship movement floats
public float speed;
public float boostSpeed;
public float backSpeed;
public float turnSpeed;
private Rigidbody[] playerRB;
[SerializeField] float[] horizontalInput;
[SerializeField] float[] accelInput;
[SerializeField] float[] backInput;
[SerializeField] bool[] AbuttonInput;
[SerializeField] bool[] XbuttonInput;
[SerializeField] Light laserIndicatorLight;
[SerializeField] Transform LaserStart;
[SerializeField] float laserTime;
[SerializeField] float laserCoolTime;
[SerializeField] private bool[] canFire;
LineRenderer laserLine;
public LineRenderer enemyLine;
public Transform enemyTrans;
public int playerNumber;
void Start (){
laserIndicatorLight.color = Color.white;
playerRB = new Rigidbody[4];
laserLine = gameObject.GetComponent<LineRenderer> ();
horizontalInput = new float[4];
accelInput = new float[4];
backInput = new float[4];
canFire = new bool[4];
AbuttonInput = new bool[4];
XbuttonInput = new bool[4];
canFire [playerNumber] = true;
playerRB [playerNumber] = gameObject.GetComponent<Rigidbody> ();
}
void Update (){
horizontalInput[0] = Input.GetAxis ("Horizontal 1");
accelInput[0] = Input.GetAxis ("Accel 1");
backInput[0] = Input.GetAxis ("Back 1");
AbuttonInput [0] = Input.GetButton ("A button 1");
XbuttonInput [0] = Input.GetButton ("X button 1");
horizontalInput[1] = Input.GetAxis ("Horizontal 2");
accelInput[1] = Input.GetAxis ("Accel 2");
backInput[1] = Input.GetAxis ("Back 2");
AbuttonInput [1] = Input.GetButton ("A button 2");
XbuttonInput [1] = Input.GetButton ("X button 2");
playerRB[playerNumber].AddTorque (0, horizontalInput[playerNumber] * turnSpeed, 0);
playerRB[playerNumber].AddForce (transform.forward * -accelInput[playerNumber] * speed, ForceMode.VelocityChange);
// playerRB[playerNumber].AddForce (transform.forward * backInput[playerNumber] * -backSpeed, ForceMode.Impulse);
if (XbuttonInput[playerNumber] == true) {
playerRB[playerNumber].AddForce (transform.forward * boostSpeed, ForceMode.VelocityChange);
}
if (AbuttonInput[playerNumber] == true) {
StartCoroutine (Laser ());
}
RaycastHit hit;
Physics.Raycast(LaserStart.position, transform.forward, out hit);
laserLine.SetPosition(0, LaserStart.position);
laserLine.SetPosition(1, hit.point + hit.normal );
enemyLine.SetPosition(0, transform.position);
enemyLine.SetPosition(1, enemyTrans.position );
}
private IEnumerator Laser(){
if (canFire[playerNumber] == true) {
canFire[playerNumber] = false;
laserIndicatorLight.color = Color.red;
laserLine.enabled = true;
yield return new WaitForSeconds (laserTime);
laserLine.enabled = false;
yield return new WaitForSeconds (laserCoolTime);
canFire[playerNumber] = true;
laserIndicatorLight.color = Color.white;
}
}
void FixedUpdate (){
}
}
so basically to re-cap, i set my game up to be 2 player, and it's working. but the players are swaped around, even though it was working, and i changed nothing.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612065435im_/https://answers.unity.com/themes/thub/images/avi.jpg)