Skip to content

Latest commit

 

History

History
66 lines (44 loc) · 2.71 KB

04_playercontrol.md

File metadata and controls

66 lines (44 loc) · 2.71 KB

PlayerControl

The PlayerControl object is spawned for each player that joins a game lobby and despawned at the end of the game. It is responsible for a player's character interacting with the game and its other players. It has two sibling objects: the PlayerPhysics and CustomNetworkTransform objects.

Serialize

When the PlayerControl is being spawned, the game first writes the information in the table below.

Type Name Description
boolean Is New Whether or not the PlayerControl object already existed before sending a spawn message for it

Note: This will be true on the PlayerControl object of a joining player as seen from the clients that are already in a game lobby, and false on the PlayerControl objects of the clients already in the game lobby as seen from the joining player

When the PlayerControl object is being spawned, as well as when it is sending data (via 0x01 Data), the game also writes the information in the table below.

Type Name Description
byte Player ID The ID of the player that is being spawned

Refer to the pseudocode below for an example.

writer.writePackedUInt32(playerControlNetId);

if (isSpawning) {
    writer.startMessage(0);
    writer.writeBoolean(isNew);
}

writer.writeByte(playerId);

if (isSpawning) {
    writer.endMessage();
}

Deserialize

When the PlayerControl has been spawned, the game first reads the information in the table below.

Type Name Description
boolean Is New Whether or not the PlayerControl object already existed before receiving a spawn message for it

Note: This will be true on the PlayerControl object of a joining player as seen from the clients that are already in a game lobby, and false on the PlayerControl objects of the clients already in the game lobby as seen from the joining player

When the PlayerControl object has been spawned, as well as when it is receiving data (via 0x01 Data), the game also reads the information in the table below.

Type Name Description
byte Player ID The ID of the player that is being spawned

Refer to the pseudocode below for an example.

long playerControlNetId = reader.readPackedUInt32();

if (isSpawning) {
    reader = reader.readMessage();
    boolean isNew = reader.readBoolean();
}

byte playerId = reader.readByte();

Previous section: GameData
Next section: MiraShipStatus