---
title: あなたのキャラクターの身長を測る
slug: world-sdk-guide-ja/HlUZUhgoLY_7nnVseTmn4
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

このガイドでは、ローカルプレイヤーのZEPETOキャラクターの体型に応じて高さを測定する方法を示します。



### ステップ 1 : キャラクターの高さ値を取得するスクリプトを書く

シーンにGameObjectを追加し、以下のCharacterHeightの例スクリプトを追加します。

```typescript
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 : 実行

再生ボタンをクリックして実行すると、コンソールログにキャラクターの高さの値が表示されます。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-lpGLOsNjPVzJwPLTSC0VP-20240904-102420.png)



:::hint{type="success"}
👍 **ヒント**

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

:::hint{type="info"}
**📘 SkinnedMeshRenderer.localBounds**

- [https://docs.unity3d.com/Manual/class-SkinnedMeshRenderer.html](https://docs.unity3d.com/Manual/class-SkinnedMeshRenderer.html)
- [https://docs.unity3d.com/2020.3/Documentation/ScriptReference/SkinnedMeshRenderer-localBounds.html](https://docs.unity3d.com/2020.3/Documentation/ScriptReference/SkinnedMeshRenderer-localBounds.html)
:::

