创造你的世界
玩家与角色:提示
测量你角色的身高
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) { // 使用 waitforendofframe 准确获取角色的关节位置。 yield new waitforendofframe(); // 获取头部位置。 const headposition = zepeto character getsocket(knowsockets head upper) position; // 获取左脚位置。 const leftfootposition = zepeto character zepetoanimator getbonetransform(humanbodybones leftfoot) position; // 获取右脚位置。 const rightfootposition = zepeto character zepetoanimator getbonetransform(humanbodybones rightfoot) position; // 计算两脚之间的中点。 const charactercenter = vector3 lerp(leftfootposition, rightfootposition, 0 5); // 计算头部与角色中心之间的距离。 const characterheight = vector3 distance(headposition, charactercenter); console log(`角色高度从地面 ${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