question

Justin Heasman avatar image
Justin Heasman asked

Correct Way To Sync with PlayFab Custom Server

What is the correct way to synchronize a changing player value across clients. For example, a players health. You wouldn't want to keep the health on the client so the server must keep this. Would you just use a Network Send command or is there a way to sync the value? Would you use [SyncVar] or equivalent?

Same goes for something like position and rotation. What would be the correct way to sync this across clients?

Do you still need to use Rpc functions?

Just trying to get my head around StrangeloC and how is differs from using straight unity Networking.

Many thanks.

Custom Game Servers
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Since you've tagged this "Custom Game Servers", the answer is that it's going vary hugely depending on what language, libraries, and tools you're using for your server executable, as well as the specific needs of your game style and design. Generally speaking, the server is authoritative about things like health, and updates to that player would be frequent (a lot of action games target around 6 to 10 updates per second). When communicating that to other players, there are a lot of ways you could approach this. If you have only a few players, you could update everyone fairly frequently (which would be the effect with a SyncVar), whereas with a lot of players, you may want to consider only updating players based upon "interest" (a combination of how recently the two players interacted, how far away the other player is, and how close the other player is to the center of the view frustum). But position information is usually more of a partnership with the client (so to speak). In order to have a good user experience, the player needs to have his inputs translate into immediate response on his local client, and shouldn't be "yanked" to a different position more than rarely. The server then follows a "trust, but verify" system for validating the player's movements, to ensure he's not cheating. On the client side, you'll use some form of prediction for the position of other players, and then use interpolation to move those players to their "true" positions based upon what you hear from the server.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Justin Heasman avatar image Justin Heasman commented ·

Make a lot of sense thanks and yes it was for a Custom Game Server. We are already filtering based on "interest" to reduce traffic. We used your PlayFabGameServer as a base when we created the Game Server. Building in Unity and uploading to PlayFab Custom Game Servers.

The game is a topdown 2D game, so the things that need "syncing" are 2d position and rotation.

We are checking for 2D collisions with enemies and other players.

The server creates and manages enemies.

To confirm.

Health and things like that should be stored on the server and send to the client(s).

Position should be managed on the client (for speed), but sent to the server for validation and sending to other clients in interest area.

Enemies are managed on the server

What about collisions? Managed on client and validated on server again?

0 Likes 0 ·
brendan avatar image
brendan answered

I can't really say that those things should always be on the server or not - that's up to your requirements. The way to think of it is this: Whatever you need the server to be authoritative about needs to live on the server. The clients will have their local version, which may be different from time to time, but eventually needs to sync to what the server is saying. You'll definitely want to have some form of collision detection on the server, but that's to make sure the client isn't cheating (going though walls, etc.). Depending on your need, this may be a sphere test moving from previous to current position. If the client is cheating, force it to a "legal" position. For other collision checks, it depends - what kind of collision is it? If you mean the client's avatar encountering walls (or other players), that's usually done on the client (and then the server's check re-validates there). If it's something that can cause damage, like bullets, you need to decide how you want to handle authority. If another player is in my crosshairs and I pull the trigger, that player not taking damage is a poor experience. Alternately, if I've just rounded a corner, suddenly taking damage from a player who shouldn't be able to see me is a poor experience. Most games favor the former, since the player getting hit may not really be aware of where the shot came from. At the same time, you need to monitor for cheating in this as well - a player who blocks packets for a quarter second to get an advantage on taking a shot can be hard to detect, but good logging on the server will usually help to detect this.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Justin Heasman avatar image Justin Heasman commented ·

Most helpful - thanks Brendan.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.