20 lines
1 KiB
JavaScript
20 lines
1 KiB
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
// Layer: shared-runtime/motion
|
||
|
|
// Shared deterministic panic wander used by burning creatures.
|
||
|
|
(function (global) {
|
||
|
|
function updateBurnWanderAngle(entity, dt, opts = {}) {
|
||
|
|
const worldRef = entity?.world || null;
|
||
|
|
entity.burnTurnTimer = Math.max(0, Number(entity.burnTurnTimer || 0) - dt);
|
||
|
|
if (entity.burnTurnTimer <= 0) {
|
||
|
|
const bucket = Math.floor((worldRef?.time || 0) * (opts.bucketScale || 5));
|
||
|
|
entity.burnWanderAngle = deterministicAngle(worldRef, opts.angleKey || "burn-angle", entity, bucket);
|
||
|
|
entity.burnTurnTimer = deterministicRange(worldRef, opts.turnKey || "burn-turn", opts.turnMin ?? 0.10, opts.turnMax ?? 0.34, entity);
|
||
|
|
} else {
|
||
|
|
entity.burnWanderAngle += deterministicRange(worldRef, opts.jitterKey || "burn-jitter", opts.jitterMin ?? -8.0, opts.jitterMax ?? 8.0, entity) * dt;
|
||
|
|
}
|
||
|
|
return entity.burnWanderAngle || 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
global.TarinaiBurnMotionUtil = Object.freeze({ updateBurnWanderAngle });
|
||
|
|
})(typeof window !== "undefined" ? window : globalThis);
|