From 361739fbe909a30cce7475173fd2b27e41fc45d2 Mon Sep 17 00:00:00 2001 From: Ray Brinzer Date: Sat, 28 Sep 2024 22:36:30 -0400 Subject: [PATCH] This patch fixes (or at least compensates for) a bug in animateEntity which causes rotation to sometimes go the wrong way. --- monks-active-tiles.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/monks-active-tiles.js b/monks-active-tiles.js index 4e81ba5..d49def8 100644 --- a/monks-active-tiles.js +++ b/monks-active-tiles.js @@ -1553,14 +1553,23 @@ export class MonksActiveTiles { animations["movement"] = attributes; //if (positionChange) // object.position.set(from.x ?? to.x, from.y ?? to.y); - let dr = to.rotation - from.rotation; - if (!isNaN(dr) && dr !== 0) { - let r = to.rotation; - if (dr > 180) r -= 360; - if (dr < -180) r += 360; - dr = r - from.rotation; - animations["rotation"] = [{ attribute: "rotation", from: (from.rotation * (Math.PI / 180)), to: (r * (Math.PI / 180)), parent: object }]; // Do not use Math.toRadians because that will normalise the number + + + let whence = from.rotation % 360; // This fix suggests a problem elsewhere + let dr = to.rotation - whence; + + if (dr) { + const DEG_TO_RAD = Math.PI / 180; + let r = (dr + 540) % 360 - 180; + + animations["rotation"] = [{ + attribute: "rotation", + from: whence * DEG_TO_RAD, + to: (whence + r) * DEG_TO_RAD, + parent: object + }]; } + let hasAlpha = false; if (from.alpha != undefined && to.alpha != undefined && from.alpha != to.alpha) { animations["alpha"] = [{ parent: object, attribute: 'alpha', from: from.alpha, to: to.alpha }];