Guides
Log In

ZEPETOPlayer

ZepetoPlayer is a character instance unit that allows creating, deleting, and managing character in a multiplayer World content.

Using each Player's UserId value, you can Load/Unload the character instance in the Scene.

There are 2 types of Players.

  • Local Player: character instance where the local user can control the character him/herself (includes the Controller/Camera component)
  • Player: character instance where multiplayer content can be loaded (does not include the Controller/Camera component)

Create/delete Player

Instantiate Player in a Single Player World

Players can be instantiated using the ZEPETO ID configured through WorldService.

The WorldService.userId is unique to each player registered in the world.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { SpawnInfo, ZepetoPlayers, LocalPlayer, ZepetoCharacter } from 'ZEPETO.Character.Controller';
import { WorldService } from 'ZEPETO.World';  

export default class CharacterController extends ZepetoScriptBehaviour {    

    Start() {        
        // Grab the user id specified from logging into zepeto through the editor. 
        ZepetoPlayers.instance.CreatePlayerWithUserId(WorldService.userId, new SpawnInfo(), true);             
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {            
            let _player : LocalPlayer = ZepetoPlayers.instance.LocalPlayer;        
        });    
    }
}

Instantiate Players in a Multi Player World

When joining a room in a multiplayer world, players are instantiated using their Login UserId.

Players leaving the room must be deleted through script.

πŸ“˜

Please refer to the following guide. [Multiplay]

OnJoinPlayer(sessionId: string, player: Player) {

    // Grab the user id specified from logging into zepeto through the editor. 
    const userId = WorldService.userId;
    const isLocal = this.room.SessionId === player.sessionId;

    // Use the sessionID as a unique ID to create a zepeto character. 
    ZepetoPlayers.instance.CreatePlayerWithUserId(sessionId, userId, new SpawnInfo(), isLocal);
}

OnLeavePlayer(sessionId: string, player: Player) {

    // Use the sessionID as a unique ID to delete a zepeto character. 
    ZepetoPlayers.instance.RemovePlayer(sessionId);
}

When the ZEPETO character Instance is completely loaded/unloaded from the scene, you can bind EventListener to perform additional work by instance.

ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
 
   // Initialize LocalPlayer ..
});
 
ZepetoPlayers.instance.OnAddedPlayer.AddListener((player_id: string) => {
     
   // Initialize Each Player ..
});
 
ZepetoPlayers.instance.OnRemovedPlayer.AddListener((player_id: string) => {
       
   // Release Each Player ..        
});

Control Player

An interface for player control can be loaded to the scene from utilizing player instance and script.

For a Local Player, the user can control directly in a scene.

const target = ZepetoPlayers.instance.GetPlayer(player_id);

// 1) Move
target.character.MoveToPosition(transform.position);

// 2) Jump
if ((player.state === CharacterState.JumpIdle) || (player.state === CharacterState.JumpMove)) {
    target.character.Jump();
}

// 3) Teleport
target.character.Teleport(transform.position, transform.rotation);