Player falls through plane/floor (Multiplayer)


I created two projects: Client and Server

On my server and client I have a “Player” prefab. This prefab has a network view on it as well as a rigidbody.

My server runs the following code:

When I click on a button:

Network.InitializeServer(10, 25000, false);

When a player disconnects and I want to remove him:

void OnPlayerDisconnected(NetworkPlayer player)

When a player connects:

void OnPlayerConnected(NetworkPlayer player)
    Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);

My question is do I have to create the same level for the player on my server as well as on my client?

My client has a simple “Plane” which he falls on when he connects, but if I dont create the same “Plane” on my server my “Player” falls through the plane on the client side.

It seems highly inconvenient to do it this way. Also is this the correct way? Im unsure about where to instantiate gameobjects (Server or client)?

If you are using ‘Network.Instantiate’ you should always use it on the client that should be in ‘control’ of that object. If you instantiate it from the server-side, the server ends up having ‘control’ over every object! If you want the server to have control over when the players get instantiated, you can manage it with a player RPC. Given that every player has an object assigned to them that can receive RPCs, you can use

networkView.RPC("SpawnPlayer", networkView.owner);

and then have a procedure called ‘SpawnPlayer’ that does the network Instantiation.

Another thing- I don’t see what’s so inconvenient about the server having to create the same level as all the clients. It makes sense for the server to know as much as possible about the environment, even if the server isn’t also another player! And if the server is another player, then you don’t need to worry about the environment thing at all, because naturally they will be in the same level as everyone else.