Only 1 Player Can't See Others

Options
Hey guys, I recently picked up Photon (PUN) and have been messing with it. At first everything was going fine, I could see both my players and watch a very laggy ball bounce around. (For argument sake let's say this game is Pong except the players only rotate.)

If I launch the game... and the editor is the master, it'll work fine. It sees player 2, and even sees him move around. Player 2 does not see Master.

However... if the client is master, the editor can see both players except the second player spawns at 0,0,0 and doesn't move. Editor (as player two) spawns correctly and can move. Client doesn't see Player 2.

This is the error that pops up in the editor every time.



And here are my scripts... if you know Photon they'll look very familiar...

NetworkManager.cs
using UnityEngine; using System.Collections; public class NetworkManager : MonoBehaviour { const string VERSION = "v0.0.1"; public string roomName = "Default"; public string player1 = "player1Prefab"; public string player2 = "player2Prefab"; public Transform p1Spawn; // Use this for initialization void Start () { PhotonNetwork.ConnectUsingSettings (VERSION); } void OnJoinedLobby() { RoomOptions roomOptions = new RoomOptions () { isVisible = false, maxPlayers = 4 }; PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default); } void OnJoinedRoom() { if (PhotonNetwork.isMasterClient == true) { PhotonNetwork.Instantiate (player1, new Vector3 (-9.27f, -4.7f, 0), p1Spawn.rotation, 0); } else if(PhotonNetwork.isMasterClient == false) { PhotonNetwork.Instantiate (player2, new Vector3 (9.33f, 4.56f, 0), p1Spawn.rotation, 0); } Debug.Log("Connected to Room"); } }

NetworkPlayer.cs
using UnityEngine; using System.Collections; public class NetworkPlayer : Photon.MonoBehaviour { //State Machine bool isAlive = true; Vector3 position; Quaternion rotation; float lerpSmoothing = 450f; // Use this for initialization void Start () { if (photonView.isMine) { GetComponentInChildren<Player> ().enabled = true; } else { StartCoroutine (Alive ()); } } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext (transform.position); stream.SendNext (transform.rotation); } else { this.position = (Vector3)stream.ReceiveNext (); this.rotation = (Quaternion)stream.ReceiveNext (); } } //State Machine public IEnumerator Alive() { while (isAlive) { transform.position = Vector3.Lerp (transform.position, this.position, Time.deltaTime * lerpSmoothing); transform.rotation = Quaternion.Lerp (transform.rotation, this.rotation, Time.deltaTime * lerpSmoothing); yield return null; } } }

Any help is highly appreciated! Thank you!

Comments

  • SKyTech6
    Options
    Bump... ? <3
  • vadim
    Options
    Hi,
    Can you log arguments passed to Quaternion.Lerp call?
    What is the call stack for errors you pasted? (This stack is printed in frame below log window).
    Do you think that lerpSmoothing = 450f is good for interpolation? This value = 5 in PUN demos. Did you try lesser values?
  • SKyTech6
    Options
    vadim said:

    Hi,
    Can you log arguments passed to Quaternion.Lerp call?
    What is the call stack for errors you pasted? (This stack is printed in frame below log window).
    Do you think that lerpSmoothing = 450f is good for interpolation? This value = 5 in PUN demos. Did you try lesser values?

    Changing lerpSmoothing to 5f fixed those errors from happening now. Except now no matter if Player 1 or 2, the Editor always spawns the other player at 0,0,0 instead of the correct position and doesn't show them move.
  • vadim
    Options
    What you mean? Other player is not seen in scene? Then how do you know it's position?
  • SKyTech6
    Options
    In first post I said that the client doesn't see the other player (the editor).

    Editor sees themselves AND client. Client is shown on Editor at 0,0,0 when actually they are in their actual spawn position and moving around.

    ----------

    Overall I think this thread can be closed... I'm not sure this community is active enough for me to want to take this dive.

    UNet might be under-developed in comparison, but at least the community is more responsive and helping. And the amount of tutorials is much wider.

    --------

    Thanks for your help, vadim. I may return one day...