Synchronization practices for other players and monsters in MMORPG

1) In MMORPG, the synchronization method between other players and monsters
​2) AssetBundle is encrypted/decrypted by Offset
3) The API difference of loading prefabs
4) About the use of MaterialPropertyBlock


This is the 340th UWA technical knowledge sharing push, which selects hot topics in the UWA community, covers UWA Q&A, community posts and other technical knowledge points, to help everyone master and learn more comprehensively.

Network

Q: Regarding the synchronization of other players and monsters in MMORPG:

The current practice is that both the monster and the player have a state machine, and the state change is set according to the state sent by the server. The action is not over yet, and the server sends a new status. At this time, if you directly set the new status, it will behave abnormally and the position will not be synchronized (for example, the client has not moved yet, and it is closed again due to freeze or delay. In the attack state, if you attack directly at this time, it will show the situation of moving and attacking).

Because I have no experience in this area before, I checked other people's practices on the Internet, saying that it is necessary to predict the status of other characters. If there is a synchronization exception, use interpolation to quickly restore the abnormal object to a normal state.

So:
1. Are other players and synchronization done with a state machine plus prediction?
2. What is the general method of monster synchronization? Is it similar to other players?
3. What points should be paid attention to when doing synchronization?

A:

  1. The synchronization of other players and monsters generally adopts a combination of state synchronization and state prediction. State synchronization means that the server synchronizes the state of all roles to the client, and the client updates the state machine of the role according to these states. State prediction means that the client predicts the state of other roles according to its own state machine, and updates its own view according to these prediction results. The predicted result needs to be verified through synchronization with the server. If the predicted result is inconsistent with the server's result, state correction is required.

  2. The synchronization of monsters is similar to the synchronization of other players, and requires a combination of state synchronization and state prediction. The difference is that the monster is usually controlled by the server, so the server can control the state and behavior of the monster more precisely, which can reduce the amount of prediction and synchronization of the client, thereby improving the efficiency of synchronization.

  3. When doing synchronization, you need to pay attention to the following points:

  • The frequency of state synchronization should be high enough to ensure that the state of the role can be synchronized to the client in time to reduce the error of state prediction.
  • State prediction should be as accurate as possible, and appropriate algorithms and parameters should be used to improve the accuracy of prediction.
  • When the client freezes or lags, it is necessary to use interpolation and correction methods to quickly restore the character to a normal state to avoid out-of-sync positions.
  • It is necessary to verify the character's movement and attack behaviors to avoid cheating and cheating.
  • For the communication between the client and the server, reliable protocols and encryption methods are required to ensure the security and stability of the communication.

Thanks to NG Zhou @UWA Q&A community for providing answers


AssetBundle

Q: Pack AssetBundle and want to use the offset to simply encrypt:

App version use:
AssetBundle.LoadFromFile(filePath, 0, offset)

But the WebGL version uses:
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(urlPath);
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);

The relevant interface was not found, do you have any ideas?

A: Use UnityWebRequest on the WebGL platform to send a network request to obtain the AssetBundle file, decrypt it in the memory after obtaining it, and then store the decrypted AssetBundle content in the memory.

To load AssetBundle in memory, you can use AssetBundle.LoadFromMemoryAsync(byte[] buffer) method or AssetBundle.LoadFromMemory(byte[] buffer) method.

Thanks to NG Zhou @UWA Q&A community for providing answers


Loading

Q: What is the specific difference between the two APIs for loading prefabs, PrefabUtility.LoadPrefabContents and AssetDatabase.LoadAssetAtPath?

I have tried the test and it feels similar, and there is not much difference in speed:
PrefabUtility.SavaAsPrefabAsset is required to save and PrefabUtility.UnloadPrefabContents is released after PrefabUtility.LoadPrefabContents; after AssetDatabase.LoadAssetAtPath, use EditorUtility.SetDirty to mark, and then AssetDatabase.SaveAssets to save.

In response to the above questions, experienced friends are welcome to go to the community to exchange and share:
UWA Q & A | Game Developer Interactive Q & A Community | Yuhu Technology


Rendering

Q: For the 3D mahjong project, there is one material ball for each tile. I use a mahjong prefab without a material ball, and then instantiate the prefab when creating mahjong tiles, find and assign the corresponding material ball according to the face value of the tile, GetComponent().shareMaterial = XXXXX.

The Shader used by the shader is Complex Lit in URP.

There is a requirement that when clicking on the mahjong tiles in hand, modify the color of the cards that have already been played (of the same board) on the table, but cannot affect the color of the tiles in hand. So I used the SetPropertyBlock method of MaterialPropertyBlock to modify the color value of the played card, but it didn't take effect.

There is a prompt "MaterialPropertyBlock is used to Modify these values" under the Inspector of the played material ball. There are also some answers on the Internet, but I still don't understand. What is the correct process and practice?

In response to the above questions, experienced friends are welcome to go to the community to exchange and share:
UWA Q & A | Game Developer Interactive Q & A Community | Yuhu Technology

The cover image comes from the Internet


That's all for today's sharing. Life has a limit but knowledge has no limit. In the long development cycle, the problems we encountered are just the tip of the iceberg. The UWA community is willing to accompany you to explore and share together. More developers are welcome to join the UWA community.

UWA official website: www.uwa4d.com
UWA community: community.uwa4d.com

 

Guess you like

Origin blog.csdn.net/UWA4D/article/details/131510268