Tuesday, March 25, 2014

Networking and player owned object spawning

I keep having to drop back to basics with networking. I always try some bastardised version of authoritative and client server from grabbing snippets here and there, then confusing who owns what and how the clients behave.

Right, to put it down step by step for myself later; simple server creation via Network.InitializeServer and spawning of the server players prefab under OnServerInitialized. When a player connects, I notice it in OnPlayerConnected but do not spawn the players prefab here (my previous shots made this player owned by the server, which caused me confusion wrangling the items later on. I did have it working, but it was muddled in my head and seemed overly complicated for what I wanted)

Instead, spawn the player in OnConnectedToServer so that there is a clear separation of client/server making the scripting classes easier to read and use.

Now, I use a base class for all other items that need to exist or move relative to the origin based camera. All it does is toggle the render flags on the objects attached and stores a "relative to origin" vector3. When a player spawns, say, a radar satellite, it needs to be grabbed by the other players application and rendered in the right place.

And wa'hey


No comments:

Post a Comment