CREATE YOUR WORLD
Players & Characters: Basic

ZEPETO Character

17min
zepetocharacter is basic zepeto character instance unit for loading in a world scene to control the zepetocharacter, add the following import statement to the script import { zepetocharacter } from 'zepeto character controller'; zepetocharacter api this api creates and removes zepeto character instances, including animator controller and character controller components api description createbyzepetoid(zepetoid string, spawninfo spawninfo, complete system action$1) use a zepeto id to generate a zepeto character instance mainly used for npc character creation createbyuserid(userid string, spawninfo spawninfo, complete system action$1) create a zepeto character instance with userid mainly used for npc character creation removecharacter(character zepetocharacter) delete the character instance this api creates zepeto character model instances, excluding the animator controller and character controller components zepeto id this is the id value that the user directly specifies and uses within the zepeto app user id this is a unique id value that distinguishes users within the zepeto system, and is not a value exposed on the ui you can check it using a script if you're interested in the zepetocharacter api, refer to the documentation please refer to the following guide \[ zepeto character controller api https //developer zepeto me/docs/character controller/ ] create/delete character import { zepetoscriptbehaviour } from 'zepeto script'; import { spawninfo, zepetocharacter, zepetocharactercreator } from 'zepeto character controller'; import { button } from 'unityengine ui'; import { gameobject, object, vector3 } from 'unityengine'; import { worldservice } from 'zepeto world'; export default class samplescript extends zepetoscriptbehaviour { public zepetoid string; public removeclonecharacterbutton button; public removeclonecharactermodelbutton button; private clonecharacter zepetocharacter; private clonecharactermodel gameobject; start() { // create a new instance of the spawninfo class const firstclonespawninfo = new spawninfo(); firstclonespawninfo position = new vector3(0,0,1); const secondclonespawninfo = new spawninfo(); secondclonespawninfo position = new vector3(0,0,3); // create a `zepetocharacter` using zepetoid zepetocharactercreator createbyzepetoid(this zepetoid, firstclonespawninfo, (character zepetocharacter) => { this clonecharacter = character; }); // create a `zepetocharactermodel` using zepetoid zepetocharactercreator createmodelbyzepetoid(this zepetoid, secondclonespawninfo, (object) => { this clonecharactermodel = object; }); // create a `zepetocharacter` using userid / zepetocharactercreator createbyuserid(worldservice userid, new spawninfo(), (character zepetocharacter) => { this clonecharacter = character; }) // create a `zepetocharactermodel` using userid zepetocharactercreator createmodelbyuserid(worldservice userid, new spawninfo(), (object) => { this clonecharactermodel = object; }) / // set up a click event for the `removeclonecharacterbutton` to remove the clone character this removeclonecharacterbutton onclick addlistener(() => { zepetocharactercreator removecharacter(this clonecharacter); }); // set up a click event for the `removeclonecharactermodelbutton` to destroy the clone character model this removeclonecharactermodelbutton onclick addlistener(() => { object destroy(this clonecharactermodel); }); } } if you run the example, you can see that the charactermodel on the left is created without the animator controller and character controller components as shown below control character an interface where you can directly control the character will be provided through the script from a character instance in a scene api description movetoposition(position vector3) move the character to position movecontinuously(direction vector3) move continuously (update) in the direction the character is looking at movecontinuously(direction vector2) move continuously (update) in the direction the character is looking at stopmoving() stop the character from moving jump() character jumps to the jump power set doublejump() character double jumps with the currently set doublejump power (applicable only when using motioncontroller v2) teleport(position unityengine vector3, rotation unityengine quaternion) character instantly moves to transform setgesture(gesture unityengine animationclip) for the specified animationclip, the character motion is played while setgesture is running, the user's control inputs are not applied to the character when animationclip's loop option is turned on, it continues to play until cancelgesture() is called cancelgesture() stop playback of the currently playing animation clip through setgesture() when cancelgesture() is executed, the user's control input is applied to the character control again control character example code import { zepetoscriptbehaviour } from 'zepeto script' import {spawninfo, zepetocharacter, zepetocharactercreator} from "zepeto character controller"; import { worldservice } from 'zepeto world'; import {animationclip, vector3, waitforseconds } from 'unityengine'; export default class characteractionsample extends zepetoscriptbehaviour { public targetposition vector3; public dancegesture animationclip; private clonecharacter zepetocharacter; start() { // create a `zepetocharacter` using `zepetocharactercreator createbyuserid` zepetocharactercreator createbyuserid(worldservice userid, new spawninfo(), (character zepetocharacter) => { // assign the created character to ` clonecharacter` this clonecharacter = character; // execute `actioncoroutine()` as a coroutine this startcoroutine(this actioncoroutine()); }) } actioncoroutine() { yield new waitforseconds(3); // move ` clonecharacter` to `targetposition` after wait for 3 seconds this clonecharacter movetoposition(this targetposition); yield new waitforseconds(1); // make ` clonecharacter` jump after wait for 1 seconds this clonecharacter jump(); yield new waitforseconds(1); // set the gesture of ` clonecharacter` to `dancegesture` after wait for 1 seconds this clonecharacter setgesture(this dancegesture); yield new waitforseconds(3); // cancel the gesture of ` clonecharacter` after wait for 3 seconds this clonecharacter cancelgesture(); } } if you run the example, you can see that the cloned character performs the specified actions in order as follows 📘 please refer to the following guide \[ creating an npc docid\ xrbs8ofq7t8vhvdjzsvnj ] motion state the api related to the motion state of the zepeto character is as follows api description motionstate usedoublejump = (boolean); set whether the character can use doublejump motionstate doublejumppower = (number); set the character's doublejump power motionstate uselandingroll = (boolean); set whether to use the character's landingroll motionstate landingrollspeed = (number); set the character's landingroll speed value motionstate usemoveturn = (boolean); set whether to use moveturn for the character motionstate gravity = (number); set the character's gravity value motionstate currentjumpstate you can check the character's current jumping state \ none = 1, jumpidle = 0, jumpmove = 1, jumpdash = 2, jumpdouble = 3 motionstate currentlandingstate you can check the character's current landing status \ none = 1, landingslight = 0, landingdeep = 1, landingroll = 2 motionstate currentmovestate you can check the current movement status of your character \ none = 1, movewalk = 0, moverun = 1 motion state example code import { zepetoscriptbehaviour } from 'zepeto script' import { custommotiondata, spawninfo, zepetocharacter, zepetocharactercreator, zepetoplayer, localplayer, zepetoplayers } from "zepeto character controller"; import { worldservice } from 'zepeto world'; import { button } from 'unityengine ui'; export default class motionsample extends zepetoscriptbehaviour { public jumpbutton button; private clonecharacter zepetocharacter; start() { zepetocharactercreator createbyuserid(worldservice userid, new spawninfo(), (character zepetocharacter) => { // assign the created character to ` clonecharacter` this clonecharacter = character; // set various properties of `motionstate` in ` clonecharacter` this clonecharacter motionstate usedoublejump = true; this clonecharacter motionstate usedoublejump = true; this clonecharacter motionstate uselandingroll = true; this clonecharacter motionstate usemoveturn = true; this clonecharacter motionstate gravity = 1; }) this jumpbutton onclick addlistener(() => { this clonecharacter jump(); }); } update() { // check if ` clonecharacter` is not null if (this clonecharacter != null) { // print the current jump state of `motionstate` in ` clonecharacter` console log(`current jump state ${this clonecharacter motionstate currentjumpstate}`); // print the current landing state of `motionstate` in ` clonecharacter` console log(`current landing state ${this clonecharacter motionstate currentlandingstate}`); // print the current move state of `motionstate` in ` clonecharacter` console log(`current move state ${this clonecharacter motionstate currentmovestate}`); } } } controlling zepeto character animator api to control zepeto character animator api description statemachine constraintstateanimation starting from version 1 6 0 of zepeto world, transition of animation played in characterstatemachine can be on/off according to characterstate of motion v2 \ true turn off zepetocharacter currentstate, which is affected by controller input, and control the desired animation clip 👍 example of using constraintstateanimation you want your character to use a swimming animation instead of a walking animation you can apply a swimming animation clip to a new state and fix the state through constraintstateanimation if you want to use gesture animation while moving a character, you can apply a gesture animation clip to a new state and move the character with the fixed state using constraintstateanimation this can be used when you want to forcibly play a specific animation while temporarily ignoring the parameters values applied to the animator state zepetoanimator unityengine animator functions are available in the form of zepetoanimator for example, if you want to set an integer value for a specific character animator "state" parameter, you can use zepetoanimator setinteger("state", 1); for more detailed usage, please refer to the unityengine animator documentation and the sample script below 📘 unityengine animator https //docs unity3d com/scriptreference/animator html https //docs unity3d com/scriptreference/animator html example code for controlling zepeto character animator an example of animator control of a local player zepeto character controlled by the player import { toggle } from 'unityengine ui'; import { spawninfo, zepetocharacter, zepetoplayers } from 'zepeto character controller'; import { zepetoscriptbehaviour } from 'zepeto script' import { worldservice } from 'zepeto world'; import { animator } from "unityengine"; export default class samplescript extends zepetoscriptbehaviour { public testtogle toggle; private zepetocharacter zepetocharacter; start() { // local player creation code (please delete this section if you are already using local player creation code elsewhere) zepetoplayers instance createplayerwithuserid(worldservice userid, new spawninfo(), true); // code for setting the created local player as a zepeto character zepetoplayers instance onaddedlocalplayer addlistener(() => { this zepetocharacter = zepetoplayers instance localplayer zepetoplayer character; // setinteger example const statetype = animator stringtohash("state"); this zepetocharacter zepetoanimator setinteger(statetype, 30); // statemachine constraintstateanimation this testtogle onvaluechanged addlistener((isactive bool)=>{ this zepetocharacter statemachine constraintstateanimation = isactive; console log(isactive); }); }); } } if you run the example, you can see that when the value of statemachine constraintstateanimation is true, the trasition of animation played in characterstatemachine is off if you set the statemachine constraintstateanimation value to false, it will return to its original state controlling charactershadow starting from version 1 11 3 of zepeto charactercontroller package, an interface has been added to access the zepetocharacter shadow object api specifications charactershadow component interface class charactershadow extends unityengine monobehaviour { public target unityengine transform; public autosynctransform boolean; } target represents the object that serves as the reference for adjusting the transform of the charactershadow object \ by default, the zepeto character is set as the target the transform of the charactershadow object is adjusted based on the bottom of the specified character autosynctransform a flag value that determines whether to adjust the position of the shadow \ the default value is true with this, you can control the shadow of the zepeto character at runtime below is an example code that uses a toggle to turn the shadow on and off import { zepetoscriptbehaviour } from 'zepeto script' import { zepetocharacter, charactershadow, zepetoplayer, zepetoplayers } from 'zepeto character controller'; import { toggle } from 'unityengine ui'; export default class shadowcontroller extends zepetoscriptbehaviour { public shadowtoggle toggle; private charactershadow charactershadow; private localcharacter zepetocharacter; start() { zepetoplayers instance onaddedlocalplayer addlistener(() => { this localcharacter = zepetoplayers instance localplayer zepetoplayer character; this charactershadow = this localcharacter context getcomponentinchildren\<charactershadow>(); console log(this charactershadow\ autosynctransform); }); this shadowtoggle onvaluechanged addlistener((isactive bool)=>{ this charactershadow\ gameobject setactive(isactive); }); } }