Prompt specification
Build or customize the Three.js 3D scene "Variable Load Bridge Crossing" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Variable Load Bridge Crossing
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/variable-load-bridge-crossing-x3448
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: variable load bridge crossing. Create a playable counterweight bridge puzzle where the player's carried load changes torque. Provide visible values, bounded motion, and a reset that restores all weights. Return one self-contained HTML file.
Working Three.js Starter (variable-load-bridge-crossing-x3448):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Variable Load — Counterweight Bridge</title>
<style>
:root {
color-scheme: dark;
--cyan: #67e8f9;
--orange: #ffad5c;
--purple: #bd9cff;
--green: #68f5a5;
--red: #ff6b79;
--panel: rgba(10, 17, 34, 0.84);
--border: rgba(174, 209, 255, 0.18);
--muted: #93a7c5;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #07101f;
color: #edf6ff;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
color: inherit;
cursor: pointer;
}
button:disabled {
cursor: default;
opacity: 0.38;
}
#app, #app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
border-radius: 16px;
}
#objective {
position: absolute;
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 17px 18px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 8px;
font-size: clamp(21px, 2.4vw, 30px);
line-height: 1.05;
}
.subtle {
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.goal {
margin-top: 13px;
padding: 11px 12px;
border: 1px solid rgba(103, 232, 249, 0.22);
background: rgba(103, 232, 249, 0.06);
border-radius: 11px;
color: #d8faff;
font-size: 13px;
}
.progress-wrap {
margin-top: 14px;
}
.progress-label {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 11px;
margin-bottom: 6px;
}
.progress-track {
height: 7px;
overflow: hidden;
background: rgba(255,255,255,0.09);
border-radius: 99px;
}
#progressFill {
height: 100%;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, #42cbe7, #7ef0b2);
transition: width 0.08s linear;
}
#telemetry {
position: absolute;
top: 18px;
right: 18px;
width: min(320px, calc(100vw - 36px));
padding: 15px 16px;
}
.telemetry-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
}
.readout {
display: grid;
grid-template-columns: 1fr auto;
align-items: baseline;
gap: 8px;
padding: 6px 0;
border-bottom: 1px solid rgba(255,255,255,0.055);
}
.readout-label {
color: var(--muted);
font-size: 11px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.readout-value {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
font-weight: 800;
text-align: right;
}
.detail {
grid-column: 1 / -1;
color: #7588a8;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-align: right;
margin-top: -3px;
}
#cargoValue { color: var(--cyan); }
#counterValue { color: var(--orange); }
#netValue { color: #fff; }
.angle-section {
margin-top: 12px;
}
.angle-row {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 8px;
}
#angleValue {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 20px;
font-weight: 850;
}
#balanceLabel {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
color: var(--red);
}
.angle-track {
position: relative;
height: 13px;
border-radius: 99px;
background: linear-gradient(90deg, #ff6473 0%, #e4ae55 25%, #68f5a5 45%, #68f5a5 55%, #e4ae55 75%, #ff6473 100%);
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.safe-zone {
position: absolute;
left: 45%;
width: 10%;
top: -3px;
bottom: -3px;
border-left: 1px solid rgba(255,255,255,0.75);
border-right: 1px solid rgba(255,255,255,0.75);
background: rgba(255,255,255,0.18);
}
#angleNeedle {
position: absolute;
top: -5px;
width: 3px;
height: 23px;
border-radius: 2px;
background: white;
box-shadow: 0 0 8px rgba(255,255,255,0.8);
transform: translateX(-50%);
left: 50%;
}
#balanceNote {
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
#inventory {
position: absolute;
left: 18px;
bottom: 18px;
width: min(360px, calc(100vw - 36px));
padding: 13px 15px;
}
.crate-list {
display: grid;
gap: 7px;
margin-top: 9px;
}
.crate-chip {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
min-height: 28px;
color: #b9c9df;
font-size: 11px;
}
.crate-swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--c);
box-shadow: 0 0 10px color-mix(in srgb, var(--c), transparent 35%);
}
.crate-status {
color: #7185a4;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
#controls {
position: absolute;
right: 18px;
bottom: 18px;
width: min(420px, calc(100vw - 36px));
padding: 12px;
}
#prompt {
min-height: 37px;
display: flex;
align-items: center;
color: #dcecff;
font-size: 12px;
line-height: 1.35;
padding: 2px 3px 10px;
}
.button-row {
display: flex;
gap: 7px;
flex-wrap: wrap;
}
.control-button {
min-height: 39px;
border: 1px solid rgba(255,255,255,0.13);
border-radius: 10px;
background: rgba(255,255,255,0.065);
padding: 8px 12px;
font-size: 12px;
font-weight: 750;
transition: background 0.15s, transform 0.08s;
}
.control-button:hover:not(:disabled) {
background: rgba(103, 232, 249, 0.13);
border-color: rgba(103, 232, 249, 0.35);
}
.control-button:active:not(:disabled) {
transform: translateY(1px);
}
.control-button.primary {
background: rgba(103, 232, 249, 0.16);
border-color: rgba(103, 232, 249, 0.38);
color: #d9fbff;
}
.key-help {
margin-top: 9px;
color: #7386a3;
font-size: 10px;
line-height: 1.35;
}
#hintPanel {
display: none;
margin-top: 10px;
padding: 10px 11px;
border-radius: 10px;
border: 1px solid rgba(255, 173, 92, 0.25);
background: rgba(255, 173, 92, 0.07);
color: #ffe0bd;
font-size: 11px;
line-height: 1.45;
}
#hintPanel.show { display: block; }
#toast {
position: fixed;
left: 50%;
top: 22px;
transform: translate(-50%, -18px);
z-index: 20;
max-width: min(560px, calc(100vw - 30px));
padding: 11px 15px;
border-radius: 11px;
border: 1px solid rgba(103, 232, 249, 0.3);
background: rgba(8, 18, 36, 0.94);
color: #e9fbff;
box-shadow: 0 12px 35px rgba(0,0,0,0.35);
font-size: 12px;
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 0.18s, transform 0.18s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.modal {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
padding: 18px;
background: rgba(3, 8, 18, 0.68);
backdrop-filter: blur(8px);
}
.modal[hidden] { display: none; }
.modal-card {
width: min(590px, 100%);
padding: clamp(22px, 4vw, 34px);
border-radius: 22px;
border: 1px solid rgba(146, 208, 255, 0.25);
background: linear-gradient(145deg, rgba(17, 29, 51, 0.97), rgba(7, 14, 28, 0.97));
box-shadow: 0 30px 100px rgba(0,0,0,0.52);
}
.modal-card h2 {
margin: 7px 0 12px;
font-size: clamp(28px, 6vw, 48px);
line-height: 1;
}
.modal-card p {
color: #aebed3;
line-height: 1.55;
font-size: 14px;
}
.formula {
margin: 18px 0;
padding: 13px;
border-radius: 12px;
background: rgba(255,255,255,0.055);
border: 1px solid rgba(255,255,255,0.08);
color: #dff8ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.55;
}
.modal-card .control-button {
min-height: 46px;
padding-inline: 20px;
background: var(--cyan);
color: #06101c;
border: none;
}
#win .modal-card {
border-color: rgba(104, 245, 165, 0.35);
}
#winStats {
color: #bffed7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
line-height: 1.7;
}
@media (max-width: 760px) {
#objective {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
#objective .subtle { display: none; }
#objective .goal { margin-top: 8px; padding: 8px 10px; }
.progress-wrap { margin-top: 9px; }
#telemetry {
top: auto;
right: 10px;
bottom: 112px;
width: 245px;
padding: 11px 12px;
}
#telemetry .readout { padding: 4px 0; }
#inventory {
left: 10px;
bottom: 112px;
width: 190px;
padding: 10px;
}
.crate-list { gap: 4px; }
.crate-chip { font-size: 10px; }
#controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
}
}
@media (max-height: 650px) {
#inventory { display: none; }
#telemetry { padding: 10px 12px; }
.readout { padding: 3px 0; }
}
</style>
</head>
<body>
<div id="app"></div>
<div id="hud">
<section id="objective" class="panel">
<div class="eyebrow">Variable Load / Puzzle 01</div>
<h1>Counterweight Bridge</h1>
<div class="subtle">
Deliver the cyan payload while keeping the moving span inside its safe torque window.
</div>
<div class="goal">
<strong>Receiver manifest:</strong> cyan 3 t cargo.<br>
The 1 t operator counts as bridge load.
</div>
<div class="progress-wrap">
<div class="progress-label"><span>LOAD BAY</span><span id="positionValue">−8.75 m</span><span>RECEIVER</span></div>
<div class="progress-track"><div id="progressFill"></div></div>
</div>
</section>
<section id="telemetry" class="panel">
<div class="telemetry-head">
<div class="eyebrow">Live Telemetry</div>
<div class="live-dot"></div>
</div>
<div class="readout">
<span class="readout-label">Carried load</span>
<span id="cargoValue" class="readout-value">EMPTY</span>
<span id="cargoDetail" class="detail">1 t operator only</span>
</div>
<div class="readout">
<span class="readout-label">Drive moment</span>
<span id="driveValue" class="readout-value">+0.0 t·m</span>
<span id="driveDetail" class="detail">Operator is off the bridge</span>
</div>
<div class="readout">
<span class="readout-label">Counter moment</span>
<span id="counterValue" class="readout-value">−0.0 t·m</span>
<span id="counterDetail" class="detail">No counterweight loaded</span>
</div>
<div class="readout">
<span class="readout-label">Net moment</span>
<span id="netValue" class="readout-value">+0.0 t·m</span>
<span id="netDetail" class="detail">Safe window: ±1.25 t·m</span>
</div>
<div class="angle-section">
<div class="angle-row">
<span class="readout-label">Bridge angle</span>
<span id="angleValue">0.0°</span>
</div>
<div class="angle-track">
<div class="safe-zone"></div>
<div id="angleNeedle"></div>
</div>
<div id="balanceLabel">LEVEL</div>
<div id="balanceNote">Bridge motion is physically bounded to ±12°.</div>
</div>
</section>
<section id="inventory" class="panel">
<div class="eyebrow">Available Weights</div>
<div class="crate-list">
<div class="crate-chip" id="chip-payload" style="--c:#67e8f9">
<span class="crate-swatch"></span><span>3 t · cyan payload</span><span class="crate-status">LOAD BAY</span>
</div>
<div class="crate-chip" id="chip-heavy" style="--c:#ffad5c">
<span class="crate-swatch"></span><span>6 t · orange block</span><span class="crate-status">LOAD BAY</span>
</div>
<div class="crate-chip" id="chip-light" style="--c:#bd9cff">
<span class="crate-swatch"></span><span>1 t · violet ballast</span><span class="crate-status">LOAD BAY</span>
</div>
</div>
</section>
<section id="controls" class="panel">
<div id="prompt">Pick up a crate in the load bay.</div>
<div class="button-row">
<button id="leftBtn" class="control-button" aria-label="Move left">◀ A</button>
<button id="rightBtn" class="control-button" aria-label="Move right">D ▶</button>
<button id="actBtn" class="control-button primary">E · Lift</button>
<button id="dropBtn" class="control-button">F · Place</button>
<button id="resetBtn" class="control-button">R · Reset</button>
<button id="cameraBtn" class="control-button">View</button>
<button id="hintBtn" class="control-button">Hint</button>
</div>
<div class="key-help">
A/D or arrows: walk · E: lift · F: place/deliver · R: restore all weights · H: hint
· Drag scene: orbit · Wheel: zoom · C: reset camera
</div>
<div id="hintPanel">
<strong>Hint:</strong> Use the 6 t block in the marked 4 m bin. Then retrieve the 3 t payload and stop at
the far cyan receiver edge. At 6.00 m, drive moment = (1 + 3) × 6 = 24 t·m and counter moment =
6 × 4 = 24 t·m, giving zero net moment.
</div>
</section>
</div>
<div id="toast"></div>
<div id="intro" class="modal">
<div class="modal-card">
<div class="eyebrow">Engineering Trial</div>
<h2>Variable Load<br>Bridge</h2>
<p>
The bridge is a bounded, pivoting span. The operator and any carried crate create a forward moment,
while crates placed in the marked bins create counter-moments.
</p>
<div class="formula">
Drive moment = (1 t operator + carried cargo) × distance from pivot<br>
Counter moment = bin weight × marked lever arm<br>
Bridge angle is limited to ±12°
</div>
<p>
Move with <strong>A/D</strong> or the arrow keys. Use <strong>E</strong> to lift and
<strong>F</strong> to place or deliver. Deliver the cyan <strong>3 t</strong> payload with the span
level. <strong>R</strong> restores every weight.
</p>
<button id="startBtn" class="control-button">Enter the trial</button>
</div>
</div>
<div id="win" class="modal" hidden>
<div class="modal-card">
<div class="eyebrow" style="color:var(--green)">Load Accepted</div>
<h2>Bridge Balanced</h2>
<p>The cyan payload reached the receiver while the span remained inside the safe torque window.</p>
<div id="winStats"></div>
<button id="winResetBtn" class="control-button">Restore all weights</button>
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* --------------------------------------------------------------------------
Core constants and state
-------------------------------------------------------------------------- */
const DECK_MIN = -5.10;
const DECK_MAX = 6.00;
const DECK_Y = 2.30;
const BANK_TOP = 2.46;
const OPERATOR_MASS = 1;
const MAX_ANGLE = THREE.MathUtils.degToRad(12);
const ANGLE_PER_TORQUE = THREE.MathUtils.degToRad(0.32);
const MOMENT_TOLERANCE = 1.25;
const DELIVERY_X = 5.75;
const START_X = -8.75;
const sockets = [
{ x: -2, arm: 2, label: 'BIN 2 m' },
{ x: -4, arm: 4, label: 'BIN 4 m' }
];
const crateDefinitions = [
{
id: 'payload', name: '3 t cyan payload', weight: 3,
color: 0x67e8f9, accent: 0xbff8ff, stagingX: -8.25
},
{
id: 'heavy', name: '6 t orange block', weight: 6,
color: 0xffad5c, accent: 0xffe1b8, stagingX: -7.25
},
{
id: 'light', name: '1 t violet ballast', weight: 1,
color: 0xbd9cff, accent: 0xe7dcff, stagingX: -6.25
}
];
const state = {
started: false,
playerX: START_X,
carried: null,
angle: 0,
angularVelocity: 0,
walkPhase: 0,
won: false
};
const input = { left: false, right: false };
/* --------------------------------------------------------------------------
Renderer, scene, lighting
-------------------------------------------------------------------------- */
const app = document.getElementById('app');
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101f);
scene.fog = new THREE.Fog(0x07101f, 22, 43);
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0x9cc8ff, 0x17213b, 1.55);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffeed3, 3.1);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x58bfff, 1.25);
rim.position.set(8, 7, -10);
scene.add(rim);
const materials = {
bank: new THREE.MeshStandardMaterial({ color: 0x243653, roughness: 0.9, flatShading: true }),
bankTop: new THREE.MeshStandardMaterial({ color: 0x334969, roughness: 0.86, flatShading: true }),
deck: new THREE.MeshStandardMaterial({ color: 0x526681, roughness: 0.74, metalShading: true }),
deckAlt: new THREE.MeshStandardMaterial({ color: 0x607995, roughness: 0.72, metalShading: true }),
rail: new THREE.MeshStandardMaterial({ color: 0x9cb3cd, roughness: 0.5, metalness: 0.35 }),
dark: new THREE.MeshStandardMaterial({ color: 0x111a2a, roughness: 0.75 }),
cyan: new THREE.MeshStandardMaterial({
color: 0x67e8f9, emissive: 0x167f96, emissiveIntensity: 0.8,
roughness: 0.38, metalness: 0.18
}),
orange: new THREE.MeshStandardMaterial({
color: 0xffad5c, emissive: 0x7a3510, emissiveIntensity: 0.5,
roughness: 0.52
})
};
function box(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function textSprite(text, options = {}) {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 160;
const ctx = canvas.getContext('2d');
ctx.fillStyle = options.background || 'rgba(7, 15, 29, 0.88)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = options.border || '#67e8f9';
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = options.color || '#e9f8ff';
ctx.font = `800 ${options.fontSize || 58}px ui-monospace, SFMono-Regular, Menlo, monospace`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.renderOrder = 20;
return sprite;
}
/* --------------------------------------------------------------------------
Voxel environment
-------------------------------------------------------------------------- */
const floor = box(scene, [26, 0.4, 10], [0, -2.15, 0],
new THREE.MeshStandardMaterial({ color: 0x0b1b31, roughness: 1 }));
floor.castShadow = false;
const grid = new THREE.GridHelper(24, 24, 0x245575, 0x17324d);
grid.position.y = -1.93;
scene.add(grid);
box(scene, [5.20, 4.40, 4.50], [-7.65, 0.25, 0], materials.bank);
box(scene, [4.50, 4.40, 4.50], [8.25, 0.25, 0], materials.bank);
box(scene, [5.20, 0.10, 4.50], [-7.65, BANK_TOP + 0.03, 0], materials.bankTop);
box(scene, [4.50, 0.10, 4.50], [8.25, BANK_TOP + 0.03, 0], materials.bankTop);
for (let x = -9.8; x < -5.1; x += 0.72) {
box(scene, [0.035, 0.018, 4.25], [x, BANK_TOP + 0.09, 0],
new THREE.MeshBasicMaterial({ color: 0x4b6888 }), false);
}
for (let x = 6.3; x < 10.3; x += 0.72) {
box(scene, [0.035, 0.018, 4.25], [x, BANK_TOP + 0.09, 0],
new THREE.MeshBasicMaterial({ color: 0x4b6888 }), false);
}
const abyssMaterial = new THREE.MeshStandardMaterial({
color: 0x164e6c, emissive: 0x0a779c, emissiveIntensity: 1.2, roughness: 0.45
});
for (let i = 0; i < 19; i++) {
const x = -5 + i * 0.58;
const height = 0.18 + ((i * 7) % 5) * 0.10;
box(scene, [0.18, height, 0.22 + (i % 3) * 0.12],
[x, -1.72 + height / 2, -0.9 + (i % 4) * 0.55], abyssMaterial, false);
}
box(scene, [1.05, 4.1, 1.05], [0, 0.10, 0], materials.dark);
box(scene, [2.1, 0.25, 2.1], [0, 2.08, 0], materials.rail);
const pivot = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.52, 3.15, 20),
new THREE.MeshStandardMaterial({ color: 0xc3d3e5, roughness: 0.35, metalness: 0.55 })
);
pivot.rotation.x = Math.PI / 2;
pivot.position.set(0, DECK_Y, 0);
pivot.castShadow = true;
scene.add(pivot);
const bridge = new THREE.Group();
bridge.position.y = DECK_Y;
scene.add(bridge);
const plankCount = 24;
const plankLength = (DECK_MAX - DECK_MIN) / plankCount;
for (let i = 0; i < plankCount; i++) {
const x = DECK_MIN + (i + 0.5) * plankLength;
const mat = i % 3 === 0 ? materials.deckAlt : materials.deck;
box(bridge, [plankLength - 0.035, 0.30, 2.30], [x, 0, 0], mat);
}
box(bridge, [11.10, 0.18, 0.13], [0.45, 0.50, -1.20], materials.rail);
box(bridge, [11.10, 0.18, 0.13], [0.45, 0.50, 1.20], materials.rail);
for (let i = 0; i <= 10; i++) {
const x = DECK_MIN + i * (DECK_MAX - DECK_MIN) / 10;
for (const z of [-1.20, 1.20]) {
box(bridge, [0.10, 0.62, 0.10], [x, 0.28, z], materials.rail);
}
}
const socketGroups = [];
for (const socket of sockets) {
const group = new THREE.Group();
group.position.x = socket.x;
bridge.add(group);
socketGroups.push(group);
box(group, [1.05, 0.08, 1.50], [0, 0.19, 0], materials.orange);
box(group, [0.10, 0.48, 0.10], [-0.47, 0.38, -0.67], materials.rail);
box(group, [0.10, 0.48, 0.10], [0.47, 0.38, -0.67], materials.rail);
box(group, [0.10, 0.48, 0.10], [-0.47, 0.38, 0.67], materials.rail);
box(group, [0.10, 0.48, 0.10], [0.47, 0.38, 0.67], materials.rail);
const label = textSprite(socket.label, {
color: '#ffe0bd', border: '#ffad5c', fontSize: 48
});
label.scale.set(1.85, 0.58, 1);
label.position.set(0, 1.30, -0.75);
group.add(label);
}
const receiverPad = box(scene, [1.05, 0.08, 2.10], [6.42, BANK_TOP + 0.10, 0], materials.cyan);
box(scene, [0.12, 1.25, 0.12], [6.80, BANK_TOP + 0.68, -1.45], materials.cyan);
box(scene, [0.12, 1.25, 0.12], [6.80, BANK_TOP + 0.68, 1.45], materials.cyan);
const loadBaySign = textSprite('LOAD BAY', {
color: '#d9faff', border: '#67e8f9', fontSize: 58
});
loadBaySign.scale.set(3.1, 0.97, 1);
loadBaySign.position.set(-7.35, 4.25, -1.65);
scene.add(loadBaySign);
const receiverSign = textSprite('RECEIVER', {
color: '#d9faff', border: '#67e8f9', fontSize: 58
});
receiverSign.scale.set(3.1, 0.97, 1);
receiverSign.position.set(8.00, 4.25, -1.65);
scene.add(receiverSign);
for (const definition of crateDefinitions) {
const pad = box(scene, [1.00, 0.045, 1.15],
[definition.stagingX, BANK_TOP + 0.09, 0],
new THREE.MeshBasicMaterial({ color: definition.color }), false);
pad.material.transparent = true;
pad.material.opacity = 0.34;
}
/* --------------------------------------------------------------------------
Crates and player
-------------------------------------------------------------------------- */
function makeCrate(definition) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: definition.color,
emissive: new THREE.Color(definition.color).multiplyScalar(0.16),
emissiveIntensity: 0.65,
roughness: 0.55,
metalness: 0.12,
flatShading: true
});
const bandMaterial = new THREE.MeshStandardMaterial({
color: definition.accent,
roughness: 0.45,
metalness: 0.25
});
box(group, [0.82, 0.82, 0.82], [0, 0.42, 0], bodyMaterial);
box(group, [0.13, 0.87, 0.87], [0, 0.42, 0], bandMaterial);
box(group, [0.87, 0.13, 0.87], [0, 0.42, 0], bandMaterial);
const label = textSprite(`${definition.weight} t`, {
color: '#07101f',
background: 'rgba(238,248,255,0.95)',
border: '#dff7ff',
fontSize: 70
});
label.scale.set(1.25, 0.39, 1);
label.position.set(0, 1.02, 0);
group.add(label);
group.userData.definition = definition;
scene.add(group);
return group;
}
for (const definition of crateDefinitions) {
definition.visual = makeCrate(definition);
definition.location = 'staging';
definition.socketIndex = null;
}
function setCrateTransform(crate) {
const visual = crate.visual;
if (crate.location === 'staging') {
scene.add(visual);
visual.position.set(crate.stagingX, BANK_TOP + 0.10, 0);
visual.rotation.set(0, 0, 0);
visual.scale.setScalar(1);
} else if (crate.location === 'held') {
player.add(visual);
visual.position.set(0.74, 0.55, 0);
visual.rotation.set(0, 0, 0);
visual.scale.setScalar(0.72);
} else if (crate.location === 'socket') {
bridge.add(visual);
visual.position.set(sockets[crate.socketIndex].x, 0.19, 0);
visual.rotation.set(0, 0, 0);
visual.scale.setScalar(1);
} else if (crate.location === 'delivered') {
scene.add(visual);
visual.position.set(6.42, BANK_TOP + 0.10, 0);
visual.rotation.set(0, 0, 0);
visual.scale.setScalar(1);
}
}
const player = new THREE.Group();
scene.add(player);
const playerBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xe7f2ff, roughness: 0.5, metalness: 0.12, flatShading: true
});
const playerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x24344f, roughness: 0.65, metalness: 0.18, flatShading: true
});
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0x67e8f9, emissive: 0x1c9eb4, emissiveIntensity: 1.15, roughness: 0.25
});
box(player, [0.54, 0.70, 0.46], [0, 0.91, 0], playerBodyMaterial);
box(player, [0.48, 0.43, 0.46], [0, 1.49, 0], playerBodyMaterial);
box(player, [0.055, 0.20, 0.34], [0.255, 1.50, 0], visorMaterial);
box(player, [0.17, 0.13, 0.18], [0, 1.27, 0], playerDarkMaterial);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(0, 0.57, -0.15);
legRight.position.set(0, 0.57, 0.15);
player.add(legLeft, legRight);
box(legLeft, [0.19, 0.58, 0.20], [0, -0.27, 0], playerDarkMaterial);
box(legRight, [0.19, 0.58, 0.20], [0, -0.27, 0], playerDarkMaterial);
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(0, 1.13, -0.34);
armRight.position.set(0, 1.13, 0.34);
player.add(armLeft, armRight);
box(armLeft, [0.16, 0.56, 0.16], [0, -0.24, 0], playerBodyMaterial);
box(armRight, [0.16, 0.56, 0.16], [0, -0.24, 0], playerBodyMaterial);
const operatorLabel = textSprite('1 t OPERATOR', {
color: '#dff8ff', border: '#7da9d7', fontSize: 42
});
operatorLabel.scale.set(1.75, 0.55, 1);
operatorLabel.position.set(0, 2.02, 0);
player.add(operatorLabel);
/* --------------------------------------------------------------------------
Physics and gameplay
-------------------------------------------------------------------------- */
function playerIsOnBridge() {
return state.playerX >= DECK_MIN && state.playerX <= DECK_MAX + 0.001;
}
function getMoments() {
const carriedWeight = state.carried ? state.carried.weight : 0;
const onBridge = playerIsOnBridge();
const drive = onBridge
? (OPERATOR_MASS + carriedWeight) * state.playerX
: 0;
let counter = 0;
const counterParts = [];
for (let i = 0; i < sockets.length; i++) {
const crate = crateDefinitions.find(c => c.socketIndex === i && c.location === 'socket');
if (crate) {
const value = crate.weight * sockets[i].arm;
counter += value;
counterParts.push(`${crate.weight} t × ${sockets[i].arm} m`);
}
}
return {
drive,
counter,
counterParts,
net: drive - counter,
carriedWeight,
onBridge
};
}
function nearestStagingCrate() {
let best = null;
let bestDistance = Infinity;
for (const crate of crateDefinitions) {
if (crate.location !== 'staging') continue;
const distance = Math.abs(crate.stagingX - state.playerX);
if (distance <= 1.0 && distance < bestDistance) {
best = crate;
bestDistance = distance;
}
}
return best;
}
function nearestSocket(occupiedOnly = false) {
let best = null;
let bestDistance = Infinity;
for (let i = 0; i < sockets.length; i++) {
const occupied = crateDefinitions.some(
crate => crate.location === 'socket' && crate.socketIndex === i
);
if (occupiedOnly && !occupied) continue;
const distance = Math.abs(sockets[i].x - state.playerX);
if (distance <= 1.05 && distance < bestDistance) {
best = { index: i, socket: sockets[i], occupied, distance };
bestDistance = distance;
}
}
return best;
}
function getContext() {
if (state.carried) {
if (state.playerX >= DELIVERY_X) {
return { kind: 'deliver', crate: state.carried };
}
const nearby = nearestSocket();
if (nearby) {
if (nearby.occupied) return { kind: 'blockedSocket', ...nearby };
return { kind: 'place', crate: state.carried, ...nearby };
}
return { kind: 'carry', crate: state.carried };
}
const staging = nearestStagingCrate();
const occupied = nearestSocket(true);
if (staging && (!occupied || Math.abs(staging.stagingX - state.playerX) <= occupied.distance)) {
return { kind: 'pickupStaging', crate: staging };
}
if (occupied) return { kind: 'pickupSocket', ...occupied };
return { kind: 'idle' };
}
function toast(message) {
const element = document.getElementById('toast');
element.textContent = message;
element.classList.add('show');
clearTimeout(toast.timer);
toast.timer = setTimeout(() => element.classList.remove('show'), 2600);
}
function liftCrate(crate, fromSocketIndex = null) {
if (state.carried) {
toast('Your hands are already full.');
return;
}
if (fromSocketIndex !== null) {
crate.location = 'held';
crate.socketIndex = null;
} else {
crate.location = 'held';
}
state.carried = crate;
setCrateTransform(crate);
}
function placeInSocket(crate, socketIndex) {
crate.location = 'socket';
crate.socketIndex = socketIndex;
state.carried = null;
setCrateTransform(crate);
toast(`${crate.weight} t block placed in the ${sockets[socketIndex].arm} m bin.`);
}
function attemptDelivery(crate) {
if (crate.id !== 'payload') {
toast('Receiver rejected this weight. The manifest requires the cyan 3 t payload.');
return;
}
const moments = getMoments();
if (Math.abs(moments.net) > MOMENT_TOLERANCE) {
toast(
`Net moment is ${formatSigned(moments.net)} t·m. Adjust the counterweight to reach ±${MOMENT_TOLERANCE.toFixed(2)} t·m.`
);
return;
}
if (Math.abs(THREE.MathUtils.radToDeg(state.angle)) > 1.2) {
toast('The bridge is still settling. Wait until the angle needle reaches the green band.');
return;
}
const finalAngle = THREE.MathUtils.radToDeg(state.angle);
crate.location = 'delivered';
crate.socketIndex = null;
state.carried = null;
state.won = true;
setCrateTransform(crate);
document.getElementById('winStats').innerHTML =
`Drive moment: ${formatSigned(moments.drive)} t·m<br>` +
`Counter moment: ${formatSigned(-moments.counter)} t·m<br>` +
`Net moment: ${formatSigned(moments.net)} t·m<br>` +
`Final bridge angle: ${finalAngle.toFixed(2)}°`;
document.getElementById('win').hidden = false;
}
function performPrimaryAction() {
const context = getContext();
if (context.kind === 'pickupStaging') {
liftCrate(context.crate);
toast(`Lifted ${context.crate.name}.`);
} else if (context.kind === 'pickupSocket') {
const crate = crateDefinitions.find(
c => c.location === 'socket' && c.socketIndex === context.index
);
if (crate) {
crate.socketIndex = null;
liftCrate(crate);
toast(`Lifted ${crate.weight} t block from the ${context.socket.arm} m bin.`);
}
}
}
function performSecondaryAction() {
if (!state.carried) {
toast('Lift a crate first.');
return;
}
const context = getContext();
if (context.kind === 'deliver') {
attemptDelivery(context.crate);
} else if (context.kind === 'place') {
placeInSocket(context.crate, context.index);
} else if (context.kind === 'blockedSocket') {
toast(`The ${context.socket.arm} m bin is already occupied.`);
} else {
toast('Move beside a counterweight bin, or carry the payload to the receiver.');
}
}
function resetGame() {
state.playerX = START_X;
state.carried = null;
state.angle = 0;
state.angularVelocity = 0;
state.walkPhase = 0;
state.won = false;
input.left = false;
input.right = false;
for (const crate of crateDefinitions) {
crate.location = 'staging';
crate.socketIndex = null;
setCrateTransform(crate);
}
document.getElementById('win').hidden = true;
document.getElementById('toast').classList.remove('show');
resetCamera();
updateUI();
}
/* --------------------------------------------------------------------------
HUD
-------------------------------------------------------------------------- */
function formatSigned(value) {
const rounded = Math.abs(value) < 0.0005 ? 0 : value;
return `${rounded >= 0 ? '+' : '−'}${Math.abs(rounded).toFixed(1)}`;
}
function updateUI() {
const moments = getMoments();
const angleDegrees = THREE.MathUtils.radToDeg(state.angle);
const balanced = Math.abs(moments.net) <= MOMENT_TOLERANCE && Math.abs(angleDegrees) <= 1.2;
document.getElementById('cargoValue').textContent = state.carried
? `${state.carried.weight} t`
: 'EMPTY';
document.getElementById('cargoDetail').textContent = state.carried
? `${state.carried.name} + 1 t operator`
: '1 t operator only';
document.getElementById('driveValue').textContent = `${formatSigned(moments.drive)} t·m`;
document.getElementById('driveDetail').textContent = moments.onBridge
? `(${OPERATOR_MASS} + ${moments.carriedWeight}) t × ${state.playerX.toFixed(2)} m`
: 'Operator is off the bridge';
document.getElementById('counterValue').textContent = `${formatSigned(-moments.counter)} t·m`;
document.getElementById('counterDetail').textContent = moments.counterParts.length
? moments.counterParts.join(' | ')
: 'No counterweight loaded';
document.getElementById('netValue').textContent = `${formatSigned(moments.net)} t·m`;
document.getElementById('netDetail').textContent = `Safe window: ±${MOMENT_TOLERANCE.toFixed(2)} t·m`;
document.getElementById('angleValue').textContent = `${angleDegrees.toFixed(1)}°`;
const needle = document.getElementById('angleNeedle');
needle.style.left = `${50 + THREE.MathUtils.clamp(angleDegrees / 12, -1, 1) * 47}%`;
const balanceLabel = document.getElementById('balanceLabel');
const balanceNote = document.getElementById('balanceNote');
if (balanced) {
balanceLabel.textContent = 'LEVEL / BALANCED';
balanceLabel.style.color = 'var(--green)';
balanceNote.textContent = 'Net moment is inside the acceptance window.';
} else {
balanceLabel.textContent = angleDegrees > 0 ? 'LEFT TIP' : 'RIGHT TIP';
balanceLabel.style.color = 'var(--red)';
balanceNote.textContent = Math.abs(moments.net) > MOMENT_TOLERANCE
? 'Counter-moment mismatch. Rearrange the orange counterweight.'
: 'The bridge is settling toward the current net moment.';
}
document.getElementById('positionValue').textContent = `${state.playerX.toFixed(2)} m`;
const progress = THREE.MathUtils.clamp(
(state.playerX - START_X) / (DECK_MAX - START_X), 0, 1
) * 100;
document.getElementById('progressFill').style.width = `${progress}%`;
for (const crate of crateDefinitions) {
const chip = document.getElementById(`chip-${crate.id}`);
const status = chip.querySelector('.crate-status');
chip.style.opacity = crate.location === 'delivered' ? '0.55' : '1';
if (crate.location === 'staging') status.textContent = 'LOAD BAY';
else if (crate.location === 'held') status.textContent = 'IN HAND';
else if (crate.location === 'socket') status.textContent = `${sockets[crate.socketIndex].arm} M BIN`;
else status.textContent = 'DELIVERED';
}
const context = getContext();
const prompt = document.getElementById('prompt');
const actButton = document.getElementById('actBtn');
const dropButton = document.getElementById('dropBtn');
if (context.kind === 'pickupStaging') {
prompt.textContent = `E · Lift ${context.crate.name} from the load bay.`;
actButton.textContent = 'E · Lift';
actButton.disabled = false;
dropButton.textContent = 'F · Place';
dropButton.disabled = true;
} else if (context.kind === 'pickupSocket') {
prompt.textContent = `E · Lift the block from the ${context.socket.arm} m counterweight bin.`;
actButton.textContent = 'E · Lift';
actButton.disabled = false;
dropButton.textContent = 'F · Place';
dropButton.disabled = true;
} else if (context.kind === 'place') {
prompt.textContent = `F · Place ${context.crate.weight} t in the ${context.socket.arm} m counterweight bin.`;
actButton.textContent = 'E · Lift';
actButton.disabled = true;
dropButton.textContent = `F · ${context.socket.arm} m Bin`;
dropButton.disabled = false;
} else if (context.kind === 'deliver') {
if (context.crate.id === 'payload') {
prompt.textContent = balanced
? 'F · Deliver the cyan 3 t payload to the receiver.'
: 'Receiver ready, but the bridge must be balanced and level before delivery.';
} else {
prompt.textContent = 'The receiver requires the cyan 3 t payload, not this block.';
}
actButton.textContent = 'E · Lift';
actButton.disabled = true;
dropButton.textContent = 'F · Deliver';
dropButton.disabled = false;
} else if (context.kind === 'blockedSocket') {
prompt.textContent = `The ${context.socket.arm} m bin is occupied. Continue toward the receiver.`;
actButton.textContent = 'E · Lift';
actButton.disabled = true;
dropButton.textContent = 'F · Occupied';
dropButton.disabled = true;
} else if (context.kind === 'carry') {
prompt.textContent = `Carrying ${context.crate.weight} t. Move to a marked bin or the cyan receiver.`;
actButton.textContent = 'E · Lift';
actButton.disabled = true;
dropButton.textContent = 'F · Place';
dropButton.disabled = true;
} else {
prompt.textContent = 'Choose a crate in the load bay, then arrange the bridge counterweight.';
actButton.textContent = 'E · Lift';
actButton.disabled = true;
dropButton.textContent = 'F · Place';
dropButton.disabled = true;
}
}
/* --------------------------------------------------------------------------
Camera controls, implemented without addons
-------------------------------------------------------------------------- */
const cameraState = {
target: new THREE.Vector3(-0.25, 1.25, 0),
yaw: 0.53,
pitch: 0.48,
radius: 19.5
};
function updateCamera() {
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + cameraState.radius * cosPitch * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.sin(cameraState.pitch),
cameraState.target.z + cameraState.radius * cosPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = 0.53;
cameraState.pitch = 0.48;
cameraState.radius = innerWidth < 760 ? 22.5 : 19.5;
updateCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener('pointerdown', event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.0045, 0.18, 1.05);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener('pointerup', endDrag);
renderer.domElement.addEventListener('pointercancel', endDrag);
renderer.domElement.addEventListener('contextmenu', event => event.preventDefault());
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
31
);
updateCamera();
}, { passive: false });
/* --------------------------------------------------------------------------
Input and UI buttons
-------------------------------------------------------------------------- */
document.getElementById('startBtn').addEventListener('click', () => {
state.started = true;
document.getElementById('intro').hidden = true;
renderer.domElement.focus();
});
document.getElementById('actBtn').addEventListener('click', performPrimaryAction);
document.getElementById('dropBtn').addEventListener('click', performSecondaryAction);
document.getElementById('resetBtn').addEventListener('click', resetGame);
document.getElementById('winResetBtn').addEventListener('click', resetGame);
document.getElementById('cameraBtn').addEventListener('click', resetCamera);
document.getElementById('hintBtn').addEventListener('click', () => {
document.getElementById('hintPanel').classList.toggle('show');
});
const leftButton = document.getElementById('leftBtn');
const rightButton = document.getElementById('rightBtn');
function bindHoldButton(element, property) {
element.addEventListener('pointerdown', event => {
event.preventDefault();
input[property] = true;
element.setPointerCapture(event.pointerId);
});
element.addEventListener('pointerup', () => { input[property] = false; });
element.addEventListener('pointercancel', () => { input[property] = false; });
element.addEventListener('lostpointercapture', () => { input[property] = false; });
}
bindHoldButton(leftButton, 'left');
bindHoldButton(rightButton, 'right');
window.addEventListener('keydown', event => {
const key = event.key.toLowerCase();
if (key === 'a' || event.key === 'ArrowLeft') {
input.left = true;
event.preventDefault();
}
if (key === 'd' || event.key === 'ArrowRight') {
input.right = true;
event.preventDefault();
}
if (event.repeat) return;
if (key === 'e') performPrimaryAction();
if (key === 'f') performSecondaryAction();
if (key === 'r') resetGame();
if (key === 'c') resetCamera();
if (key === 'h') document.getElementById('hintPanel').classList.toggle('show');
if (event.key === 'Enter' && !state.started) {
state.started = true;
document.getElementById('intro').hidden = true;
}
});
window.addEventListener('keyup', event => {
const key = event.key.toLowerCase();
if (key === 'a' || event.key === 'ArrowLeft') input.left = false;
if (key === 'd' || event.key === 'ArrowRight') input.right = false;
});
window.addEventListener('blur', () => {
input.left = false;
input.right = false;
});
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
/* --------------------------------------------------------------------------
Main loop
-------------------------------------------------------------------------- */
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
const elapsed = clock.elapsedTime;
const movement = (input.right ? 1 : 0) - (input.left ? 1 : 0);
if (movement !== 0 && !state.won) {
state.playerX = THREE.MathUtils.clamp(
state.playerX + movement * 3.15 * dt,
-9.1,
7.2
);
state.walkPhase += dt * 10;
}
const moments = getMoments();
const targetAngle = THREE.MathUtils.clamp(
-moments.net * ANGLE_PER_TORQUE,
-MAX_ANGLE,
MAX_ANGLE
);
state.angularVelocity += (targetAngle - state.angle) * 22 * dt;
state.angularVelocity *= Math.exp(-8.2 * dt);
state.angle += state.angularVelocity * dt;
if (Math.abs(state.angle) > MAX_ANGLE) {
state.angle = THREE.MathUtils.clamp(state.angle, -MAX_ANGLE, MAX_ANGLE);
state.angularVelocity *= 0.25;
}
bridge.rotation.z = state.angle;
const onBridge = playerIsOnBridge();
player.position.x = onBridge
? state.playerX * Math.cos(state.angle)
: state.playerX;
player.position.y = onBridge
? DECK_Y + 0.15 + state.playerX * Math.sin(state.angle)
: BANK_TOP;
player.rotation.z = onBridge ? state.angle : 0;
const swing = movement !== 0 ? Math.sin(state.walkPhase) * 0.42 : 0;
legLeft.rotation.z = swing;
legRight.rotation.z = -swing;
armLeft.rotation.z = -swing * 0.7;
armRight.rotation.z = swing * 0.7;
if (state.carried && state.carried.location === 'held') {
state.carried.visual.position.y = 0.55 + Math.sin(elapsed * 7) * 0.018;
}
updateUI();
renderer.render(scene, camera);
}
for (const crate of crateDefinitions) setCrateTransform(crate);
resetCamera();
updateUI();
animate();
</script>
</body>
</html>
```