Skip to content

Instantly share code, notes, and snippets.

View hobione2k's full-sized avatar

hobione hobione2k

View GitHub Profile
@hobione2k
hobione2k / timer.js
Last active May 31, 2023 04:11
ClusterScript Timer
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;
};
@hobione2k
hobione2k / intarvalTask.js
Created May 30, 2023 06:57
ClusterScript-一定間隔で実行
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;
};
@hobione2k
hobione2k / log.js
Last active May 30, 2023 07:05
ClusterScript-時刻付きログ
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;
};
@hobione2k
hobione2k / detectSignal.js
Last active April 29, 2024 19:26
ClusterScript-シグナル検出
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;
};
@hobione2k
hobione2k / subNodeCompare.js
Last active September 28, 2023 17:20
ClusterScript Beta subNode比較
const equalNode = (n1, n2) =>
n1.getGlobalPosition().equals(n2.getGlobalPosition()) &&
n1.getGlobalRotation().equals(n2.getGlobalRotation());
@hobione2k
hobione2k / dedupPlayer.js
Created September 28, 2023 15:44
ClusterScript Beta playerHandle重複排除
const dedupPlayer = (players) =>
players.filter((p, i) => players.findIndex((p2) => p2.id == p.id) === i);
@hobione2k
hobione2k / dogeza.js
Last active September 28, 2023 19:18
ClusterScipt Beta DOGEZA検出サンプル
// プレイヤー検出用コライダーに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(
@hobione2k
hobione2k / getOverlapsPlayer.js
Last active March 22, 2024 20:16
ClusterScript Beta Overlapプレイヤーを取得
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);
@hobione2k
hobione2k / attachItemToPlayer.js
Last active October 15, 2023 13:50
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);
@hobione2k
hobione2k / attachSubNodeToPlayer.js
Last active March 11, 2024 14:42
ClusterScript(Beta) SubNodeをプレイヤーにくっつけるサンプル
// インタラクトしたユーザーの頭にアイテムをくっつける
// ※アイテムスケールが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));