Hi, I’ve only just got into multi-player programming, so it’s extremely basic (and probably not written efficiently)
my error is that, both players spawn on their separate sides, and they are only able to move to their zones, but on each ‘move’ they constantly spasm from their point, as if trying to go to the other players movement choice… but it seems overridden instantly, so it flutters on the spot.
It’s a strange looking thing, and i’m pretty sure it’s something to do with my raycast, and how it’s not applying to the individual.
EDIT: it’s the other player from the screen. So example, on player ones screen, player 2 flutters. and on Screen 2, the player 1 flutters.
Their own players look still on their own screens.
Help would be great! Thanks
playerScript:
bool moveBool = false;
bool playerMoving = false;
Vector3 myVector;
void Update(){
RaycastHit rayHit = new RaycastHit ();
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Input.GetButtonDown ("Fire1") && playerMoving == false ){
if( Physics.Raycast(ray, out rayHit) && rayHit.collider.tag == "Zone" + networkManager.playerID.ToString() ){
print (rayHit.collider.name);
Vector3 dir = new Vector3(rayHit.transform.position.x, 0.5f , rayHit.transform.position.z);
moveBool = true;
myVector = dir;
}
}
if (moveBool == true) {
this.movePlayer(myVector);
}
} // End Update
void movePlayer(Vector3 newVector){
if (this.transform.position != newVector) {
playerMoving = true;
this.transform.position = Vector3.MoveTowards (transform.position, newVector, Time.deltaTime * 5f);
} else {
playerMoving = false;
moveBool = false;
}
}
multiplayerScript:
bool showRoomGUI = false;
public Transform player1Start;
public Transform player2Start;
public static int playerID = 0;
public static string playerName;
void Start(){
PhotonNetwork.ConnectUsingSettings ("Alpha 0.1");
}
void OnGUI(){
if (showRoomGUI == true) {
GUI.Button (new Rect (10, 10, 100, 20), PhotonNetwork.room.name);
}
GUI.Button (new Rect( 10,30,100,20), PhotonNetwork.connectionState.ToString ());
GUI.Button (new Rect( 10, 50,100,20), PhotonNetwork.playerList.Length.ToString());
GUI.Button (new Rect( 10, 70,150,20), "PlayerID = " + PhotonNetwork.player.ID.ToString());
if (PhotonNetwork.player.ID == 1) {
GUI.Button (new Rect( 10, 200,150,20), "Player1 button");
}
if (PhotonNetwork.player.ID == 2) {
GUI.Button (new Rect( 10, 200,150,20), "Player2 button");
}
}
void OnJoinedLobby(){
PhotonNetwork.JoinRandomRoom ();
print ("Joined lobby");
}
void OnPhotonRandomJoinFailed(){
print ("something failed");
PhotonNetwork.CreateRoom ("Room1");
}
void OnJoinedRoom(){
playerID = PhotonNetwork.player.ID;
playerName = PhotonNetwork.player.name;
showRoomGUI = true;
print ("Joined " + PhotonNetwork.room.name);
if (playerID == 1) {
GameObject player1 = PhotonNetwork.Instantiate ("player", player1Start.position, Quaternion.identity, 0);
player1.name = "player" + PhotonNetwork.player.ID.ToString ();
}
if (playerID == 2){
GameObject player2 = PhotonNetwork.Instantiate ("player", player2Start.position, Quaternion.identity, 0);
player2.name = "player" + PhotonNetwork.player.ID.ToString();
}
}//End on Joined Room
}