あなたの世界を作りなさい
プレイヤーとキャラクター: ヒント
あなたのキャラクターの身長を測る
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の高さの値を使用してキャラクターの高さを測定することです。 キャラクターの頭、帽子、アクセサリーをモデル化して上部の位置を測定したい場合は、以下のリンクを参照してください: 📘 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