This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const logLvl = () => $.getStateCompat(Tg.this, "LOG_LEVEL", T.integer); | |
const pd = (n, l = 2) => { | |
return n.toString().padStart(l, "0"); | |
}; | |
const now = () => { | |
const d = new Date(); | |
const time = `${pd(d.getHours())}:${pd(d.getMinutes())}:${pd( | |
d.getSeconds() | |
)}.${pd(d.getMilliseconds(), 3)}`; | |
return time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rad2Deg = (r) => (r * 180) / Math.PI; | |
const aimAt = (pos, target) => { | |
const dir = target.clone().sub(pos); | |
const angleY = rad2Deg(Math.atan2(dir.x, dir.z)); // Y軸回転 | |
const d = new Vector2(dir.x, dir.z).length(); | |
const angleX = -rad2Deg(Math.atan2(dir.y, d)); // X軸回転 | |
return new Quaternion().setFromEulerAngles(new Vector3(angleX, angleY, 0)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sendAll = (items, type, value) => { | |
if (items == null) return; | |
items = items.concat(); | |
while (items.length > 0) { // 送信先があれば実行 | |
const item = items.shift(); // 取り出す | |
try { | |
item.send(type, value); | |
} catch (e) { | |
items.unshift(item); // エラーになったら戻して次回に回す | |
return items; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const activePlayer = (players) => | |
players.filter((p) => p != null && p.exists()); | |
const getAllPlayer = () => { | |
const players = $.getPlayersNear($.getPosition(), Infinity); | |
return activePlayer(players); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// インタラクトしたユーザーの頭にアイテムをくっつける | |
// ※アイテムスケールが1であること | |
$.onInteract((player) => { | |
$.state.targetPlayer = player; | |
}); | |
const attachSubNodeToPlayer = (subNode, player, bone, offset) => { | |
const bonePos = player.getHumanoidBonePosition(bone); | |
const boneRot = player.getHumanoidBoneRotation(bone); | |
const globalPos = bonePos.add(offset.clone().applyQuaternion(boneRot)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// インタラクトしたユーザーの頭にアイテムをくっつける | |
$.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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dedupPlayer = (players) => | |
players.filter((p, i) => players.findIndex((p2) => p2.id == p.id) === i); | |
const activePlayer = (players) => | |
players.filter((p) => p != null && p.exists()); | |
const getOverlapsPlayer = () => { | |
// getOverlaps()から有効なプレイヤーだけ取得 | |
const overlaps = $.getOverlaps(); | |
const players = overlaps.map((o) => o.object.playerHandle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// プレイヤー検出用コライダーにOverlap Detector Shapeコンポーネントを付けること | |
// アイテムの中心(原点)が床の高さであること | |
const dedupPlayer = (players) => | |
players.filter((p, i) => players.findIndex((p2) => p2.id == p.id) === i); // 重複排除 | |
$.onUpdate((deltaTime) => { | |
// プレイヤーを取得 | |
const overlaps = $.getOverlaps(); | |
const players = dedupPlayer( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dedupPlayer = (players) => | |
players.filter((p, i) => players.findIndex((p2) => p2.id == p.id) === i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const equalNode = (n1, n2) => | |
n1.getGlobalPosition().equals(n2.getGlobalPosition()) && | |
n1.getGlobalRotation().equals(n2.getGlobalRotation()); |
NewerOlder