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 TIMER_KEY = (name) => `timer_${name}`; | |
const isTimerActive = (name) => $.state[TIMER_KEY(name)] >= 0; | |
const startTimer = (name, duration) => { | |
const key = TIMER_KEY(name); | |
if (isTimerActive(name)) return false; // この行を消すと再実行でタイマーを延長できる | |
$.state[key] = duration; | |
return true; | |
}; |
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 intervalTask = (name, interval, deltaTime) => { | |
const key = `intervalTask_${name}}`; | |
$.state[key] = ($.state[key] ?? interval) + deltaTime; | |
if ($.state[key] < interval) return false; | |
$.state[key] = 0; | |
return true; | |
}; |
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 pad = (n, l = 2) => { | |
return n.toString().padStart(l, "0"); | |
}; | |
const now = () => { | |
const d = new Date(); | |
const time = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad( | |
d.getSeconds() | |
)}.${pad(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 detectSignal = (n) => { | |
const sg = $.getStateCompat("this", n, T.double); | |
const ky = `last_${n}`; | |
const lsg = $.getStateCompat("this", ky, T.double); | |
if (sg > lsg) { | |
$.setStateCompat("this", ky, sg); | |
return true; | |
} | |
return false; | |
}; |
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()); |
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
// プレイヤー検出用コライダーに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); | |
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
// インタラクトしたユーザーの頭にアイテムをくっつける | |
$.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
// インタラクトしたユーザーの頭にアイテムをくっつける | |
// ※アイテムスケールが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)); |
OlderNewer