- Home /
Network , new player can't see the old players ?
Hi ...
Im trying to make a network game.
but I've one problem :
I created a new game on sever side , then one of the clients join to that game , after that I started the game ... in this case every things OK
but when Create and Start game on server before any clients join to game .. in this case when client connect to server , the server can see him , but client can't see the server (" new player can't see the old players that already connected " )
any idea ?
thanks
how can i make new Network.Instantiate for all old players that already in game, and these clone show just in the last player joined
this one for create the player when level loaded
function CreatePlayer ()
{
var play : GameObject = Network.Instantiate(Player,Vector3(0,1,0), Quaternion.identity,0) as GameObject;
}
when new player connect to server will check if the game started or not
function OnPlayerConnected(networkPlayer : NetworkPlayer )
{
if ( $$anonymous$$anager_Server.StartGame )
networkView.RPC("Server_Started_Game",RPC$$anonymous$$ode.Others,$$anonymous$$anager_Server.$$anonymous$$apName);
}
if yes the client will start the game and call the "CreatePlayer" function , so the server will see him . but this new client doesn't see the serever player .
Note : if the client connect to server and the server doesn't started the game yet, will add the client to the list , after press on "Start game" on server , the game will start in both Client/Server , and client and server will see each others _
Answer by Minchuilla · Apr 23, 2014 at 02:58 PM
Assuming that by "players" you mean GameObjects of other players:
Be sure that you use Network.Instantiate() this will create a copy for each player
Docs here.
When destroying GameObjects use the code in my answer in this post.
Feel free to ask more questions.
Michuilla
thank u for answering me ...
I used "Network.Instantiate()" because all the old players , see the new one , but the last one joined to the game , doesn't see any players ..
that seems strange, are you sure you arent using any groups when using Network.Instantiate();
could you give me a code sample of just a few lines please
Actually, Network.Instantiate is an RPC that is buffered so that every user that joins gets the instantiation call, so I don't know why it's not working
this one for create the player when level loaded
function CreatePlayer ()
{
var play : GameObject = Network.Instantiate(Player,Vector3(0,1,0), Quaternion.identity,0) as GameObject;
}
when new player connect to server will check if the game started or not
function OnPlayerConnected(networkPlayer : NetworkPlayer )
{
if ( $$anonymous$$anager_Server.StartGame )
networkView.RPC("Server_Started_Game",RPC$$anonymous$$ode.Others,$$anonymous$$anager_Server.$$anonymous$$apName);
}
if yes the client will start the game and call the "CreatePlayer" function , so the server will see him . but this new client doesn't see the serever player .
Note : if the client connect to server and the server doesn't started the game yet, will add the client to the list , after press on "Start game" on server , the game will start in both Client/Server , and client and server will see each others _
This seems fine except that I don't quite understand why you call "Server_Started_Game" to "RPC$$anonymous$$ode.Others"
What I would do Ins$$anonymous$$d is this:
When the server starts the game
//in server
function OnGameStarted()
{
networkView.RPC("CreatePlayer", RPC$$anonymous$$ode.AllBuffered, mapName);
}
notice that RPC$$anonymous$$ode is buffered
This code then doesn't require the function OnPlayerConnected
Hopefully the Instantiation will work correctly then