- Home /
How to sync players in multiplayer game
Hello Developers,
I am doing a MMO for web with Unity3d and Smartfox, there is a virtual world in the game, any player can login and he/she can run in the virtual world, this is the basic thing of my game.
I want to know that, how can I sync each login players on other side, suppose, 3 peoples A,B,C are login from different browsers and running in the virtual word in same direction. How can I update the position of player A on B,C side, similarly we need to update position of B on A,C side and so on.
Therefore result will be, position of each player will be same on each side(A,B,C side) on each frame.
I was tried to follow [this][1] tutorial by smartfox but PROXIMITY_LIST_UPDATE never fired.
Please let me know your suggestions and tutorials for that.
Thanks!! [1]: http://docs2x.smartfoxserver.com/AdvancedTopics/mmo-rooms
I don't know Smartfox, I am using Unity build-in networking with $$anonymous$$asterServer (RackNet). There (if Smartfox is not a simple holder and manager of connected machines, but taking care also about the players physics logic) have to be something like RPCs from clients to server and server to clients, with current local player positions, or something like NetworkViewID to identify and synchronize the players positions by serialization.
Thanks nastasache, Is your used method scalable to thousands of player online and playing game at a time?
Hi, I have tested many examples provided by Unity and some others, they are working fine with smartfox on local machine, but when I test it on live smartfox server then its lagging and sometimes its hang & crashed.
There are following way to update on other side: - OnUserVariableUpdate - Update via ExtensionResponse - Object$$anonymous$$essageRequest()
All these methods are not working with live smartfox server, its going too slow and crashed.
Please reply with your answer. Thanks!!
Did you try using UDP ins$$anonymous$$d of TCP connections. UDP is more stable. http://docs2x.smartfoxserver.com/AdvancedTopics/using-udp-protocol
Answer by adnirjhar · Jan 01, 2014 at 05:42 AM
I am still a noob at SmartFox but this is what I can suggest-
add an event listener-
SmartFox smartFox = = SmartFoxConnection.Connection;
smartFox.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, OnUserVariableUpdate);
Now in that OnUserVariableUpdate function, check the BaseEvent parameter to check if the SFSUser is smartfox.MySelf. If its not you, then spawn (if its not already spawned) or update the variables- something like this-
ArrayList changedVars = (ArrayList)evt.Params["changedVars"]; //evt is the BaseEvent Parameter
SFSUser user = (SFSUser)evt.Params["user"];
OtherPlayer.transform.position = new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue(), (float)user.GetVariable("z").GetDoubleValue());
Same question, Is this way stable when thousands of player get online and playing game at a time?
I am not sure but I think that depends on the pc where the SmartFox is installed.I didnt try for like thousands of players. But works fine with 100-150 game instances, using my pc as the server.
Your answer
Follow this Question
Related Questions
How to sync child objects of a transform in multiplayer 3 Answers
[UNET] Unable to run [Command]s on remote client 1 Answer
Multiplayer syncronisation 1 Answer
Unet Sync Particle System 1 Answer