Theory of Player and Proxy Prefab

Currently I have a nice simple single player FPS, however I would like to make a simple multiplayer game with it, just to get to grips with Unity before making a larger project. I looked into Photon however I felt I still needed to learn more about Unity and its inner working, I’m going to revert back to its default networking, plus I like the ideas of letting people run their own servers.

Now I know its probably very simple however I’m getting my self into a muddle.

Now I have two prefabs, one what the player see’s, FPS view then a proxy prefab, what the people looking at each other will see.

This is untested, I’m trying to design everything first, for all I know everything could work fine

Now with it obviously makes the FPS view for the player connected and proxyPlayer for everyone else to see.

OnNetworkInstantiate
if (networkView.isMine) {
Network.Instantiate(playerPrefab, pos, transform.rotation, 0);
}

else {
Network.Instantiate(proxyPrefab, pos, transform.rotation, 0);
}

Now what I’m having problems with is, how can I get the proxyPlayer prefab only communicate with the player it represents, I want to comminucate between the playerPrefab like position and the animation that needs playing, however like I said before it only needs to communicate with the player its representing, I don’t know any function which could help.

I was thinking at first making a script for the proxyPlayer and enable userinput if the networkview is theirs,but it doesnt create a proxyplayer if the networkview is theirs.

Look ive got myself in a muddle just trying to explain it.

Thanks for the help. Sorry if this is worded bad, just ask questions and ill explain as much as I can.

Bump.

I haven’t had my coffee yet so I might have read things wrong, but I think I see a potential problem. If you use Network.Instantiate to spawn a prefab, that specific prefab will be spawned on all connected clients. All the networkviews on these prefabs will then also have the same NetworkViewID assigned to them, which is how they can talk to each other over the network.

Your desired approach is to have different prefabs represent the player on different machines. I’m experimenting with this approach as well, because it provides better encapsulation of client and server logic. Unity’s default approach doesn’t work in this situation, so I think you have to implement your own network instantiation routines. With those, you can setup the networkviews on different prefabs to have the same networkviewid so that they can talk.

Thanks very much for the reply, I’m sure someone here on the forums has a working system like this and would be very grateful if they mentioned how they did it.

Although having different prefabs for local and remote players may be a good idea (I think) to separate the code logic, you should probably just start with having the same prefab for everybody and just disable the mesh for your locally controlled player, and instead enable your first-person arms mesh. This way, should you want to integrate a third-person view later on (or a death animation, or allow your player to show up on render-to-texture cameras or similar) then it may save you some headaches.

You can still keep the remote/local player code in different scripts if you want, instead of having if() statements, and then enable and disable them depending on what type of player it is. Also, it is the server that should be sending information on player positions (including your own) and animation, not the other clients directly.