Player synchronization

Hello!

I am attempting to synchronize the state of players using PUN with Photon Cloud.

I was following the Marco Polo tutorial, but when I got to the point of ensuring the proper player receives input, somehow it doesn't work properly. So far I have only tested with two players, but I have tested this code on separate machines with the same result.

Here is my "Quick Match" script:
using UnityEngine;
using System.Collections;

public class Quickmatch : MonoBehaviour {
	
	public uint retries = 3;
	public string gameVersion = "0.01";
	public DroneMotor droneMotor;
	
	private GameObject myPlayerObject;
	private uint currentRetriesRemaining;
	private PhotonView myPlayerPhotonView;
	
	//[System.NonSerializedAttribute]
	
	void Awake () {
		currentRetriesRemaining = retries;
	}
	
	// Use this for initialization
	void Start () {
		PhotonNetwork.ConnectUsingSettings(gameVersion);
	}
	
	void OnGUI () {
		GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
	}
	
	//Automatically jump in the game
	void OnJoinedLobby () {
		PhotonNetwork.JoinRandomRoom();
	}
	
	void OnPhotonRandomJoinFailed() {
		PhotonNetwork.CreateRoom(null);
	}
	
	void OnJoinedRoom() {
		myPlayerObject = PhotonNetwork.Instantiate("LightDrone", Vector3.zero, Quaternion.identity, 0);
		myPlayerPhotonView = myPlayerObject.GetComponent<PhotonView>();
		if (myPlayerPhotonView.isMine) {
			droneMotor = myPlayerObject.GetComponent<DroneMotor>();
			droneMotor.enabled = true;
		}

	}
	
	//retry logic
	void OnFailedToConnectToPhoton () {
		if (currentRetriesRemaining > 0) {
			currentRetriesRemaining -= 1;
			PhotonNetwork.ConnectUsingSettings(gameVersion);
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

And the player is a physics-based control. Here is my player motor:
using UnityEngine;
using System.Collections;

public class DroneMotor : MonoBehaviour {
	
	public Vector3 thrust;
	
	// Use this for initialization
	void Start () {
		
	}
	
	void FixedUpdate () {
		float _xThrust = thrust.x*Input.GetAxis("Horizontal");
		float _zThrust = thrust.z*Input.GetAxis("Vertical");
		rigidbody.AddRelativeForce(_xThrust,0.0f,_zThrust);
	}
}

The transform is the observed component right now.

The problem is when I use the controls to move the player, if no one else is connected it works fine. But, as soon as someone else connects, the controls move the wrong player.

As far as I can tell I have followed the tutorial very closely, not quite sure what is wrong.

Thanks for your help!

Comments

  • Hey, I figured it out!

    Apparently, I forgot to disable the first person camera, and re-enable it for the local client. Thus, when someone new joined you actually took over their camera :lol:

    I will leave this post in case someone else has the same issue...
  • Ah, the cam control. That sounds familiar.

    There's a paragraph about this in the Marco Polo Tutorial, too:
    http://doc.exitgames.com/v3/photonunity ... lotutorial
Sign In or Register to comment.