Hello,
I’m working on a multiplayer game, and a level has sectors. So when a sector is complete i want to move the players to a new location for the next sector. However. If someone clicks the complete sector button it moves both players for that user, but the other player still sees his position as where he last was, until he moves and maintains his position . but at that point the player who did press the button who could see the other player next to him disappears.
So i guess what i am trying to do is to move both players to a new location.
This is what i have currently:
[Command]
public void CmdStartNextSector()
{
RpcStartNextSector();
}
[ClientRpc]
void RpcStartNextSector()
{
if (_playerSectorCanvas.activeInHierarchy)
{
_playerSectorCanvas.SetActive(false);
}
if (_playerLevelCanvas.activeInHierarchy)
{
_playerLevelCanvas.SetActive(false);
}
for (int i = 0; i < _allPlayers.Count; i++)
{
_allPlayers[i].GetComponent<PlayerManager>().enabled = true;
if (_level == 1)
{
if (_sectors == 2)
{
//_allPlayers[i].transform.position = _levelOneSectorTwoSpawnPoint.transform.position;
var randLoc = new Vector3(Random.Range((_levelOneSectorTwoSpawnPoint.transform.position.x - 2f), (_levelOneSectorTwoSpawnPoint.transform.position.x + 2f)), _levelOneSectorTwoSpawnPoint.transform.position.y, _levelOneSectorTwoSpawnPoint.transform.position.z);
_allPlayers[i].GetComponent<PlayerManager>().SpawnPlayerAtLocation(randLoc);
}
}
}
}
So the Command gets called when a user clicks a complete sector button. which makes the server call as i understand a client RPC to the players to move their transform which calls a method on the Playermanager attached to the player that sets the transform position which is passed through.
It work but doesnt sync the new position to the player who hasnt clicked the button.
Any suggestions an help would be fantastic thanks
Daniel
Image for reference, player on left clicked button. 2nd player(right) hasnt moved but on left it shows he has!? : Imgur: The magic of the Internet