あなたのキャラクターの身長を測る
3 分
このガイドでは、ローカルプレイヤーのZEPETOキャラクターの体型に応じて高さを測定する方法を示します。
ステップ 1 : キャラクターの高さ値を取得するスクリプトを書く
シーンにGameObjectを追加し、以下のCharacterHeightの例スクリプトを追加します。
import { Debug, HumanBodyBones, Vector3, WaitForEndOfFrame } from 'UnityEngine';
import { LocalPlayer, ZepetoPlayers, ZepetoPlayer, KnowSockets } from 'ZEPETO.Character.Controller';
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
export default class CharacterHeight extends ZepetoScriptBehaviour {
Start() {
ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
let _player: LocalPlayer = ZepetoPlayers.instance.LocalPlayer;
this.StartCoroutine(this.CoGetZepetoHeight(_player.zepetoPlayer));
});
}
*CoGetZepetoHeight(zepeto: ZepetoPlayer) {
// Use WaitForEndOfFrame to accurately obtain the joint positions of the character.
yield new WaitForEndOfFrame();
// Get the position of the head.
const headPosition = zepeto.character.GetSocket(KnowSockets.HEAD_UPPER).position;
// Get the position of the left foot.
const leftFootPosition = zepeto.character.ZepetoAnimator.GetBoneTransform(HumanBodyBones.LeftFoot).position;
// Get the position of the right foot.
const rightFootPosition = zepeto.character.ZepetoAnimator.GetBoneTransform(HumanBodyBones.RightFoot).position;
// Calculate the midpoint between the two feet.
const characterCenter = Vector3.Lerp(leftFootPosition, rightFootPosition, 0.5);
// Calculate the distance between the head and the character center.
const characterHeight = Vector3.Distance(headPosition, characterCenter);
console.log(`Character Height From Ground: ${characterHeight}`);
}
}
スクリプトの説明
- *CoGetZepetoHeight(zepeto: ZepetoPlayer)
- 使用するには、GetSocketを使用して、キャラクターの頭のソケット位置値を取得します。
- キャラクターの底の中心の位置値を取得するには、GetBoneTransformを使用して、キャラクターの両足の位置値を取得します。
- 使用するには、Vector3.Lerpを使用して、キャラクターの底の中心位置値を取得します。
- キャラクターの頭のソケットと底の中心位置値を使用して、キャラクターの高さ値を取得します。
ステップ 2 : 実行
再生ボタンをクリックして実行すると、コンソールログにキャラクターの高さの値が表示されます。

👍 ヒント
- 例での高さを測定する方法は、HeadSocketの高さの値を使用してキャラクターの高さを測定することです。
- キャラクターの頭、帽子、アクセサリーをモデル化して上部の位置を測定したい場合は、以下のリンクを参照してください: