From 8432c5f7c3796140eec06bc3b0d30bdb6172f0ed Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 8 Apr 2026 16:24:06 +0200 Subject: [PATCH] fix: match object rotation to cell canvas rotation in dungeons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two issues caused objects to float relative to dungeon map: 1. rotAngle used (heading + PI) but canvas uses (PI - heading) - these differ: sin(x+PI) = -sin(x) vs sin(PI-x) = sin(x) 2. Object dy was negated, but 180° heading offset already handles N/S - double N/S flip caused objects to drift with heading changes Co-Authored-By: Claude Opus 4.6 (1M context) --- static/script.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/static/script.js b/static/script.js index f405585d..85e2909f 100644 --- a/static/script.js +++ b/static/script.js @@ -3969,8 +3969,8 @@ function updateRadarWindow(msg) { ctx.stroke(); // Rotate world by heading so player facing = up on canvas - // In dungeons, add 180° to match UB's (heading - 180) rotation - const rotAngle = isDungeon ? headingRad + Math.PI : headingRad; + // In dungeons, use (PI - heading) to match UB's canvas rotation + const rotAngle = isDungeon ? (Math.PI - headingRad) : headingRad; // Draw objects and cache positions for click hit-testing const cosA = Math.cos(rotAngle); @@ -3987,7 +3987,9 @@ function updateRadarWindow(msg) { } const dx = dX * cosA - dY * sinA; - const dy = -(dX * sinA + dY * cosA); + // In dungeons, don't negate dy (180° heading offset handles N/S) + // In overworld, negate for north-up + const dy = isDungeon ? (dX * sinA + dY * cosA) : -(dX * sinA + dY * cosA); const px = cx + dx * scale; const py = cy + dy * scale;