Implements a portal through which the ZEPETO character can teleport to two different points.
STEP 1 : Setting the teleport target point
- Implement the ZEPETO character creation code in Scene as a default.
Please refer to the following guide. [Create a ZEPETO Character]
- Create points to teleport to.
- For this guide, we will refer to them as A and B points.
- Create a Hierarchy > 3D Object > Plane, and rename it to Plane_A.
- Add a Portal object that will initiate a teleport.
- Be sure to add a Collider to interact with the object.
- Adjust the size of the area to detect collisions.
- Make sure to check Is Trigger.
- Be sure to add a Collider to interact with the object.
- Create a total of 2 teleportation points in the same way.
- Adjust the Position so that the points do not overlap.
STEP 2 : Write a script
- Create a Project > Create > ZEPETO > TypeScript and rename it to Teleport.
- Write a sample script like below.
- Logic to teleport with destinationObject when a collision with a ZEPETO character is detected in the collider area of the object to which the script is attached.
import { Collider, Vector3, Quaternion, GameObject } from 'UnityEngine';
import { SpawnInfo, ZepetoCharacter, ZepetoPlayer, ZepetoPlayers } from 'ZEPETO.Character.Controller';
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
export default class Teleport extends ZepetoScriptBehaviour {
// The destination object to be teleported to
public destinationObject: GameObject;
private _localCharacter: ZepetoCharacter;
Start() {
// Find the local player and Set it to _localCharacter
ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
this._localCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character;
});
}
OnTriggerEnter(collider: Collider) {
// Do not execute the function if _localCharacter is not set yet or if the collided gameObject is not _localCharacter
if (this._localCharacter == null || collider.gameObject != this._localCharacter.gameObject) {
return;
}
// Teleport the _localCharacter to the position of destinationObject
this._localCharacter.Teleport(this.destinationObject.transform.position, Quaternion.identity);
}
}
- After you finish writing the script, add the script to the Portal object that will initiate the teleport.
- In the inspector, assign the Destination Object.
- Destination Object : a portal object to arrive at the end of the teleport.
STEP 3 : Run
Teleport the ZEPETO character from point A to point B when it is near the portal.
Caution
- This guide only handles teleporting of Local Players that I manipulate.
- In the case of multiplayer worlds, synchronization of the location of other players is additionally required.
- Using the synchronization component of the multiplayer sample, position synchronization is easy to implement.
Multiplay Sample - Zepeto Multiplay Component
https://github.com/naverz/zepeto-multiplay-example/tree/main/Assets/Zepeto Multiplay Component