|
Kanda Players 0.7.0
|
The Kanda SDK uses a combination of local and remote player representations to support multiplayer functionality. Understanding the difference between these player types, their spawning order, and their structure is crucial for developers working with SDK players.
Players in this package are composed of multiple parts, each represented as a separate entity:
These player parts are created as root-level entities, not in a traditional hierarchical structure. This flat structure offers several benefits:
Local players represent the user's own character and view in the game world. They are spawned on the client side and are fully controlled by the local user's input.
LocalPlayerPart componentLocalPlayerSpawnClientSystem checks if a PlayerOrigin component with LocalPlayerPart exists in the scene.LocalPlayerSpawner in the world to instantiate the appropriate prefabs for each player part based on the client's device type.PlayerInfo component data on the origin, including the device type and player ID.Remote players represent other users in the multiplayer session. They are spawned on the server and then replicated to all clients.
RemotePlayerPart componentGhostOwnerIsLocal component if they have a local counterpartRequestRemotePresenceCommand RPC to the server using the RemotePlayerSpawnClientSystem once the local player is in the game and doesn't have a RemotePresenceRequested component.RemotePlayerSpawnServerSystem receives this request and processes it.RemotePlayerSpawner to instantiate the appropriate prefabs for each player part based on the requesting client's device type.PlayerInfo data and initial transforms.LinkedEntityGroup for automatic cleanup on disconnect.The synchronization process ensures that remote player representations match their local counterparts:
SynchronizePlayerPartClientSystem handles the synchronization:LocalTransform data of the local part to the MovableInput component of the remote part.PredictedMovableSystem then applies this input to update the remote player's position and rotation.The CacheRespawnPointServerSystem continuously caches target respawn transforms for PlayerOrigin entities:
PlayerHead downwards to find a valid teleport floor.RespawnPoint buffer.The spawning process typically follows this order:
LocalPlayerSpawnClientSystemRemotePlayerSpawnClientSystem sends the RequestRemotePresenceCommandRemotePlayerSpawnServerSystem creates the remote player entitiesLocalPlayerSpawner and RemotePlayerSpawner.LocalPlayerPart and RemotePlayerPart components when implementing player-specific logic.PlayerOrigin, PlayerHead and PlayerHand components are used to identify specific parts of both local and remote players.