Studio GuideWorld SDK Guide
Log In

Create a ZEPETO Character

STEP 1 : Adding the ZEPETO Players component

In the Hierarchy window, select ZEPETO → ZepetoPlayers tab.


An object called ZepetoPlayers will be automatically created as shown below.

ZepetoPlayers is a component that manages character controller modules within the World.

Set values for character control and related functions can be set in the Inspector window.

757

STEP 2 : To Load Character

Once the CharacterController setting is complete, use the provided script to load a character.

Add a GameObject in the Scene and add the ZEPETOScript as shown below.


You can load ZEPETO characters with controllers directly to the Scene.

Enter the ZEPETO ID in [ZEPETO_ID] to load the character.

These loaded characters are called local player, and are ZEPETO characters that users can control directly from their own devices.


Script for loading a ZEPETO character with a specific ZEPETO ID

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

export default class CharacterController extends ZepetoScriptBehaviour {

    Start() {
        ZepetoPlayers.instance.CreatePlayerWithZepetoId("", "[ZEPETO_ID]", new SpawnInfo(), true);
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            const player: LocalPlayer = ZepetoPlayers.instance.LocalPlayer;
        });
    }
}

❗️

Caution

  • If you use this code, you will only play with the avatar of a specific ZEPETO ID.
  • When you launch your world, you will need to modify your code to be based on the ZEPETO ID of the user who accessed your world, instead of the ZEPETO ID you entered in your code. Please use the script below.

Script for loading the character of the logged-in ID

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(() => {           
            const player: LocalPlayer = ZepetoPlayers.instance.LocalPlayer;       
        });   
    }
}

❗️

Caution

  • Please make sure that there is only one local player creation code in the client script.
  • If multiple identical players are created, the CreatePlayerWithUserId() script may be being called elsewhere.

STEP 3 : Run

Use the [▶︎(play)] button at the center of the screen to check that the CharacterController is working properly.

CharacterController has a common character control Key Mapping for each Input Event corresponding to the device (PC/Mobile). Thus, the loaded character can be controlled in a Scene regardless of the platform.

On a PC, characters and cameras can be operated with a mouse. On a mobile device, characters and cameras can be operated with a virtual pad as shown in the screenshots below.

👍

The following input interfaces are supported for character control:

PC

  • Move: Keyboard arrows, WASD
  • Jump: Space
  • Double Jump : (Left) Shift
  • Zoom: Mouse wheel
  • Rotate: Screen drag

Mobile

  • Move: (Bottom left screen)virtual pad
  • Jump: (Bottom right screen)virtual pad button
  • Zoom: (Two fingers)screen drag
  • Rotate: (One finger)screen drag

STEP 4: Change the start position of the ZEPETO character

The start position of the ZEPETO character is created at UnityEngine.Vector3(0,0,0) unless otherwise set.

The rotation value is also generated at an angle of UnityEngine.Quaternion.Euler(0,0,0).

The character spawn position and rotation values are set using ZepetoPlayers.instance.CreatePlayerWithUserId(WorldService.userId, new SpawnInfo(), true); the function's argument, SpawnInfo(), will be generated.

So you can set the desired value for SpawnInfo() before calling the character creation function to make sure it spawns at a specific location.

We have pre-placed a 3D Object > Cube at location (0,0,0) on the map.

If you change the spawn location value for the character to the following, it will spawn on top of the Cube.

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

export default class CharacterController extends ZepetoScriptBehaviour {

    Start() {
        // Set Character Spawn Position
        const spawnInfo = new SpawnInfo();
        spawnInfo.position = new Vector3(0,2,0);
        // Set Character Spawn Rotation
        spawnInfo.rotation = Quaternion.Euler(0,0,0);

        // Grab the user id specified from logging into zepeto through the editor.
        ZepetoPlayers.instance.CreatePlayerWithUserId(WorldService.userId, spawnInfo, true);
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            const player: LocalPlayer = ZepetoPlayers.instance.LocalPlayer;
        });
    }
}

Use the Play button in the center of the screen to check the creation of the character.


If you change the position and orientation values, you can also create a character lying down like this.

// Set Character Spawn Position
const spawnInfo = new SpawnInfo();
spawnInfo.position = new Vector3(2,1,2);
// Set Character Spawn Rotation
spawnInfo.rotation = Quaternion.Euler(90,0,0);