Skip to content

Instantly share code, notes, and snippets.

@hobione2k
Last active October 15, 2023 13:50
Show Gist options
  • Save hobione2k/39e882ef36e35f621a8829060577a115 to your computer and use it in GitHub Desktop.
Save hobione2k/39e882ef36e35f621a8829060577a115 to your computer and use it in GitHub Desktop.
ClusterScript Beta アイテムをプレイヤーにくっつける(Item直接)
// インタラクトしたユーザーの頭にアイテムをくっつける
$.onInteract((player) => {
$.state.targetPlayer = player;
});
const attachToPlayer = (player, bone, offset) => {
const bonePosition = player.getHumanoidBonePosition(bone);
const boneRotation = player.getHumanoidBoneRotation(bone);
const position = bonePosition.add(offset.clone().applyQuaternion(boneRotation));
$.setPosition(position);
$.setRotation(boneRotation);
};
$.onUpdate((deltaTime) => {
const player = $.state.targetPlayer;
if(player!=null && player.exists()) {
attachToPlayer(player, HumanoidBone.Head, new Vector3(0, 0.5, 0)); // 対象プレイヤー、頭ボーン、オフセットを指定
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment