Player position in home device.

Options
hello

i am looking for some solution. i thing with below image it will be clear what i want to do in my game play with photon server.i am really frustrated with this question. please help me. in my game play when i join Room home player should be at 1 player position. and when any other player connect within same room than in its gameplay it should be at center position and 1st player position change. please provide some solution i have used photnview.ismine but its no worth of using it. its glad to getting any guidance or sample code or any refere example of such game.

Thanks in Advance.


Comments

  • Velo
    Velo
    edited January 2016
    Options
    Hmm, in my game I did a round-about way of spawning players at certain positions. However, in your case you want to move players according to when they join. It is somewhat complicated I think. But, it is possible as far as I know. What I did was spawn an "owning object" with a photon view for each player that joins. This owning object will let you know which player you are dealing with.

    I think the two biggest functions you should work with are the "OnJoinedRoom" callback function and the "OnPlayerConnected" function. You need some logic in one of your scripts that says "If this is the first player in the room (i.e. the master client), then spawn that player at a certain location (probably in OnJoinedRoom function).

    Then, in the "OnPlayerConnected" function, you work with the second, third, fourth, etc...... players that join the game. A really cool array/list of players is provided with "PhotonNetwork.playerList.Length". With this, you can tell which player is #1, #2, #3, and so on.

    I will give you some example code from my game. But this is pretty intricately tied to other gameobjects and functions, so not everything you need is in this code.....but it is an example of what I'm using. Hopefully you might be able to figure something out on your own (as your game needs are different than mine).

    Example code (sorry I don't know why it's outlined in white):

    public void OnJoinedRoom() { Debug.Log("We have joined a room!"); //instanceOfChineseSoldier1 = PhotonNetwork.Instantiate("ChineseSoldier1", new Vector3(Random.Range(2.0f, 9.0f), 200, 5), Quaternion.identity, 0); instanceOfOwnerGameObject = PhotonNetwork.Instantiate("OwnerGameObject", new Vector3(-200, 200, -200), Quaternion.identity, 0); //Game logic: if this is the only player, we're the first player in the room, so spawn at //a given location (currently spawning at spawn location #1). if (PhotonNetwork.playerList.Length == 1) { instanceOfBarracks1 = PhotonNetwork.Instantiate("Barracks1", thisGameManagerScript.spawnLocationsList[0], playerBarracks1.transform.rotation, 0); Camera.main.transform.position = new Vector3(5.7f, 208.0f, -6.2f); //Set this variable on the game manager script which will allow me to assign unit and attack //team numbers (and layers) depending on which player this is. thisGameManagerScript.photonPlayerNumber = 1; } } //If we are not the first player to connect, then execute this function public void OnPhotonPlayerConnected(PhotonPlayer player) { //In this callback function, have the "master client" control what happens when new players join or are //connected. In this case, the master client will call an RPC function on all the other clients. This //RPC function determines if (PhotonNetwork.isMasterClient == true) { //Second player to join the game should spawn at the second spawn point (kept in a list on the //GameManagerScript). if (PhotonNetwork.playerList.Length == 2) { //Call the given RPC function on the newly connected client, with the given parameters thisPhotonView.RPC("SpawnPlayersCameraAtPoint", PhotonTargets.All, new Vector3(91.8f, 208.0f, 9.4f), player.ID, 1); //Set this variable on the game manager script which will allow me to assign unit and attack //team numbers (and layers) depending on which player this is. thisPhotonView.RPC("AssignPhotonPlayerNumber", PhotonTargets.All, player.ID, 2); } //Spawn the third player at the third spawn location (currently hard coded) if (PhotonNetwork.playerList.Length == 3) { //Call the given RPC function on the newly connected client, with the given parameters thisPhotonView.RPC("SpawnPlayersCameraAtPoint", PhotonTargets.All, new Vector3(37.9f, 208.0f, 54.8f), player.ID, 2); //Set this variable on the game manager script which will allow me to assign unit and attack //team numbers (and layers) depending on which player this is. thisPhotonView.RPC("AssignPhotonPlayerNumber", PhotonTargets.All, player.ID, 3); } } }
  • Thanks for reply. But cant understand what you have done with your code and guidance. can you elaborate please...