Photon Networking: Moving all players vr
Hello im Adrian and I am having a problem with the Networking part in my game if anyone can tell me what I did wrong or if you can give me some tips that would be awesome.
Here is the NetworkManager script
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public Camera standbyCamera;
SpawnSpot [] spawnSpots;
void Start () {
spawnSpots= GameObject.FindObjectsOfType<SpawnSpot> ();
Connect ();
}
void Connect () {
PhotonNetwork.ConnectUsingSettings ("FPS V.0.01");
}
void OnGUI(){
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnJoinedLobby(){
Debug.Log ("WE joning fam");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("OnPhotonRandomRoomFailed Fam");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("WE JOIN THE ROOM FAM");
SpawnMyPlayer ();
}
void SpawnMyPlayer(){
if(spawnSpots==null) {
Debug.LogError ("Wah happen!?!?");
return;
}
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range(0,spawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Player1", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.enabled = false;
myPlayerGO.GetComponent<SteamVR_ControllerManager>().enabled=true;
myPlayerGO.GetComponent<MeshRenderer>().enabled=true;
myPlayerGO.GetComponent<Nettwork>().enabled=true;
myPlayerGO.transform.FindChild ("Controller (left)").gameObject.SetActive (true);
myPlayerGO.transform.FindChild ("Controller (right)").gameObject.SetActive (true);
myPlayerGO.transform.FindChild ("Cube").gameObject.SetActive (true);
myPlayerGO.transform.FindChild ("Camera (head)").gameObject.SetActive (true);
myPlayerGO.transform.FindChild ("eyevr").gameObject.SetActive (true);
}
}
Here is the sync script
using UnityEngine;
using System.Collections;
public class Nettwork :Photon.MonoBehaviour {
public GameObject avatar;
public GameObject righthand;
public Transform playerGlobal;
public Transform playerLocal;
public Transform right;
public Transform rightl;
void Start ()
{
Debug.Log("i'm instantiated");
if (photonView.isMine)
{
Debug.Log("player is mine");
playerGlobal = GameObject.Find("Camera (head)").transform;
playerLocal = playerGlobal.Find("eyevr");
this.transform.SetParent(playerLocal);
this.transform.localPosition = Vector3.zero;
playerGlobal.GetComponent<Camera>().enabled=true;
playerGlobal.GetComponent<SteamVR_TrackedObject>().enabled=true;
playerGlobal.GetComponent<GUILayer>().enabled=true;
right = GameObject.Find("Controller (right)").transform;
rightl= right.Find("Model");
this.transform.SetParent(rightl);
this.transform.localPosition = Vector3.zero;
right.GetComponent<SteamVR_TrackedObject>().enabled=true;
right.GetComponent<ArcTeleporter>().enabled=true;
right.GetComponent<SteamVR_TrackedController>().enabled=true;
//avatar.SetActive(false);
Debug.Log ("IM not on");
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(playerGlobal.position);
stream.SendNext(playerGlobal.rotation);
stream.SendNext(playerLocal.localPosition);
stream.SendNext(playerLocal.localRotation);
stream.SendNext(right.position);
stream.SendNext(right.rotation);
stream.SendNext(rightl.localPosition);
stream.SendNext(rightl.localRotation);
}
else
{
this.transform.position = (Vector3)stream.ReceiveNext();
this.transform.rotation = (Quaternion)stream.ReceiveNext();
avatar.transform.localPosition = (Vector3)stream.ReceiveNext();
avatar.transform.localRotation = (Quaternion)stream.ReceiveNext();
this.transform.position = (Vector3)stream.ReceiveNext();
this.transform.rotation = (Quaternion)stream.ReceiveNext();
righthand.transform.localPosition = (Vector3)stream.ReceiveNext();
righthand.transform.localRotation = (Quaternion)stream.ReceiveNext();
}
}
}
Here is some pictures: So I put the sync script inside the Player1 prefab and added it to the Photonview like this:
And what that should do is sync the players right hand and head and activate everything inside the hands, head, etc:
And just in case here is how it all looks like: https://drive.google.com/file/d/0B01xDnOShBTVY0NJbkhCeFhHZWc/view?usp=sharing
(Player A is me Player B is the online player) So the problem is when Player B joins first he spawns in and its ok nothing is wrong, but then when Player A joins in he sees Player B and when Player A moves his hand and head, Player B mimics the same. Player B can move his player freely but he can not see anyone else in the scene nor a clone like Player A. When Player A looks down you can see the head of his player but its not moving and the head is in the ground its like Player A is on a separate camera just hovering were he should spawn. When Player B disconnects Player A teleport were Player B was and becomes Player B. When Player B joins back he sees what I was seeing. Sorry if this is a simple thing to fix but I am just a bit of a noob right now with the networking stuff and if this was confusing please feel free to ask for questions or more pictures I will be happy to send them them, and im not sure but I think I did something wrong on the Nettwork script, thank you in advance for reading this really appreciate it :D