Showing posts with label networking. Show all posts
Showing posts with label networking. Show all posts

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


Wednesday, March 19, 2014

Multiplayer enabled custom coordinate system with local area rendering.

Well, that's a long winded title. I also need to get all of these scripts sorted out and hosted somewhere for people to look at.

Custom coordinates (previous post) worked well and the localised renderer toggling worked well in conjuction with the other players.

My usual issue was the networking setup and re-learning all the things I forgot about RPC communications.
Ensuring that the NetworkView items are added and set for no state synchronisation or observed items set me back as usual. The "ownership" of items and initialisation of the known "world" objects (in this case, stand-ins for solar system objects) caused me trouble until I realised I should send those objects down to the network player via RPC instead of configuring it on server connection as that only updated the servers version.

My idea is that the local player needs a copy of these items coordinates in order to do the rendering in relation to themselves and being able to manipulate them without contention on the server.

I worry that the amount of traffic needed for a living place could be prohibitive so one of my next steps will be handing around a seed and doing some very late update synchronising.

For a starfield, there are some simple tweaks available using (in this case) multiple legacy particle generators. I'll follow up on this later as it doesn't work with repeatable results (I need to seed it). But it is rather pretty.