- Home /
How do I sync a mesh over network? (Photon)
So basically, I have a minecraft clone or whatever you want to call it, and I've made it possible to connect to rooms and play with other players, but I have a big issue: The world isn't synced. And what I mean by that it isn't synced, is that whenever a new player comes into a room which already has a player or more in it, that player that just went in gets a completely different world from the rest of the players, so ultimately, players have their own different worlds. Now I can't quite figure out why this is happening because I've set a photonview on the Chunk-prefab but that doesn't help, and yes, I've attached components to the photonview. I don't know what to do to achieve the desired effect.
So, let me explain to you what effect I want to achieve: I want players to be able to be playing in the same world based on the hosts world, so if the host gets his or her world when he or she starts the server, players joining the server will have the exact same world, and I want it to continue to be synced so whenever someone destroys a block, it gets synced to everyone else. So basically I just want a synced minecraft world.
Oh, and I just want to give you some piece of information regarding the chunks and world:
The chunks are blocks from the beginning but later they get modified into a big mesh that makes it look like it's built up of blocks, and all the faces that will never be seen on the mesh until someone destroys a block, are transparent. This is to increase the performance of the game. The world-script is set up so that whenever someone pass a certain distance to an empty chunk, the chunk gets spawned in.
Also, I'm using Photon (free) for my multiplayer and I have Unity 5 installed.
Answer by 334499p · Jul 27, 2015 at 06:40 PM
Make sure that the world is being generated with a seed using perlin noise or just Random.seed. When connecting to the masterclient request the seed integer and generate the base world client-side. When the world is loaded you could request the blocks that have been edited which would be stored in the chunks in the masterclient. Each chunk could have a giant string stored in a script that has all of the edited block positions and ids for that chunk. When the newly connected client receives the string from each chunk they would have to splice and parse each value and adjust each block accordingly. When a player edits a block they would rpc the block's position and new id to the masterclient which would add the values to the string in that edited chunk for players who join later. A separate rpc would adjust the new blocks in realtime for all clients.
Your answer
Follow this Question
Related Questions
How to network a large map with 4000+ movable objects using Photon Unity Networking? 1 Answer
Variable Sync across all clients (Photon) 0 Answers
Destroying entire parent object on one client but on the other destroying just the child. 1 Answer
Using lerp to smooth network movement causes rubber banding 1 Answer
Photon - Hide/Show Object 1 Answer