LogoLogo
English
English
  • Diarkis Help Center
  • Overview of Diarkis
  • Getting Started
    • Diarkis Server Template
    • Diarkis Client SDK
    • Tutorials
      • 1. Launch Diarkis Server in Local Environment
      • 2. Perform Connectivity Check with Test Client
      • 3. Implement Custom Command
      • Connect to Server from Diarkis Client
    • Samples
  • Diarkis Modules
    • Room Module
      • Set Up Room Module on Server
      • Room Sample
        • room_broadcast
      • Utilizing Room Module from Client
      • Additional Features of Room
    • MatchMaker Module
      • Set Up MatchMaker Module on Server
    • Field Module
      • Set Up Field Module on Server
    • P2P Module
      • Set Up P2P Module on Server
      • P2P Sample
    • DM (Direct Message) Module
      • Set Up DM Module on Server
    • Notifier Module
      • Set Up Notifier Module on Server
    • Session Module
      • Set Up Session Module on Server
    • Group Module
      • Set Up Group Module on Server
  • Diarkis Server
    • Launch Diarkis Server in Cloud Environment
      • AWS
    • Launch Diarkis Server on Windows Environment
    • MARS Server
    • UDP Server
    • TCP Server
    • HTTP Server
    • Metrics API
    • Inter-server Communication - Mesh
  • Diarkis Client
    • Runtime Library
      • Diarkis RUDP
    • Diarkis Module
      • Initialization and Termination of Diarkis Module
      • Customization of Diarkis Module
      • Logging System of Diarkis Module
      • Migration
      • Threads of Diarkis
    • Samples
      • C++
        • room_broadcast
        • directmessage_simple
        • group_sample
        • matching_and_turn
        • matchmaker_ticket
        • p2p_rudp_sample
        • session_simple
      • Unreal Engine Plugin
        • FieldWalker
      • Unity Plugin
        • FieldWalker
          • HowToReplicatePosition.md
  • Diarkis Tools
    • Diarkis CLI
      • Procedures to Switch to Diarkis CLI v3
  • References
    • API Reference
    • Release Notes
      • v1.0
      • v1.0.1
      • v1.0.2
      • v1.0.3
      • v1.0.4
      • v1.0.5
      • v1.0.6
  • Support
    • License and Billing
Powered by GitBook
On this page
  • Project Setup
  • Adding Assets

Was this helpful?

  1. Diarkis Client
  2. Samples
  3. Unity Plugin
  4. FieldWalker

HowToReplicatePosition.md

PreviousFieldWalkerNextDiarkis Tools

Last updated 1 month ago

Was this helpful?

This document explains how to synchronize the position of a GameObject using the Diarkis plugin.

Project Setup

First, create a new Unity project. Then, import the Diarkis Sample Package via the Unity Package Manager (for details, refer to the ). Finally, add a DiarkisNetworkManager object to the scene and configure the connection information to the Diarkis Server. With this, the setup is complete.

Adding Assets

To understand how to synchronize a character, we will describe the synchronization process using standard Unity assets. Create a new empty scene and follow the steps below to create a map, network logic, and a controllable character. Let's add some elements:

  • Add the InputSystem prefab to handle keyboard inputs (from Packages>Diarkis Plugin Sample>Prefabs>Common>InputSystem).

  • Replace the MainCamera object with the MainCamera from Packages>Diarkis Plugin Sample>Prefabs>CommonMainCamera.

  • Create an empty object named SpawnPosition and set the desired spawn location for the player.

  • Add a DiarkisNetworkManager object (from Packages>Diarkis Plugin Sample>Prefabs>Common>NetworkManager) and configure it according to the Diarkis server settings (e.g., Http Host: 192.168.100.12:7000, Auto Start Connect: true).

  • Add the RoomManager prefab (from Packages>Diarkis Plugin Sample>Prefabs>SceneManagers>RoomManager). If all steps have been carried out correctly, the scene structure should look as follows.

Now, you need to configure where to spawn which player prefab in the RoomManager object. First, copy the prefab from Packages>Diarkis Plugin Sample>Prefabs>MainGame>Player and place it within your assets folder like Assets>Prefabs. Developers can recreate the mesh, skeleton, animations, and code (as long as the class inherits from DiarkisSynchronizedCharacter). The complete sample script, which includes RigidBody, Animator, Camera, and user input handler, can be found at Packages>Diarkis Plugin Sample>Scripts>Sample>MainGame>DiarkiSampleSynchronizedCharacter. The Diarkis Player prefab uses this script by default, but developers can create their own implementation by implementing the functions GetLocalFrameDataPayload and EnqueueRemoteFrameData that the script inherits.

Just like the DiarkisSynchronizedPlayer class, there is a DiarkisRoomObject class that can be inherited to easily create synchronized objects in Diarkis Room modules. A basic implementation example of a room object is available at Packages>Diarkis Plugin Sample>Scripts>Sample>MainGame>DiarkiSampleRoomObject. This class demonstrates how to create a simple object with two shapes (sphere or cube) and a random color. Developers can override the UpdateProperties and GetObjectProperties functions to recreate similar classes and implement their custom object properties. The object properties, Object Properties, are of type Dictionary<string, double>. By calling SetWaitForSyncPush(true), the properties will be sent the next time RoomObjectSync Push is called.

All that remains is to add Player prefab, RoomObject prefab, and SpawnPosition to the Instance Handler parameter in the RoomManager Inspector.

Various settings can be changed in the inspector to determine how character movements are synchronized. Below are explanations for each setting:

  • MaxRemoteQueueLength: The number of payloads that can be queued remotely (it's recommended to keep this number above 50).

  • MaxFramePerPayload: The number of frames a single payload can contain (at maximum). If the character is moving, the next payload will be sent once this frame count is reached, or after the Minimum Local Payload Send Frequency delay.

  • Minimum Local Payload Send Frequency: The minimum delay for sending a payload (if this delay is reached after the last payload was sent, send it without waiting to reach the maximum frame value).

  • LocalFrameEnqueue Frequency: If set to 0, all frames are synchronized; otherwise, one frame is synchronized per delay based on this value.

  • MaxRemoteInterpolation Duration In seconds: The maximum interpolation time allowed upon receiving player movement.

  • MaxAllowedDelayInSeconds: If old remote payloads are received for some reason, they are automatically skipped.

Translated with DeepL.com (free version).

Note: For example, if the number of local frames to interpolate is 4 and the maximum number of frames per payload is 5, each payload means that 5*5=25 frames are sent, so if the FPS is 60, it is sent approximately every 60/25=~0.42 seconds.

The scene is now ready to duplicate characters and display the remotely connected players.

Readme
Scene Copy
Scene Copy
Scene Copy
Scene Copy
Scene Copy
Scene Copy