MZ Pathfinding breaks the sprites with Dot Movement

Hey there! I'm making a game using the Action RPG plugin set, which is based off of the DotMoveSystem plugin, by Unagi Ootoro.

I've been trying to use this pathfinding method for NPCs:

Code:
this.moveStraight(this.findDirectionTo(x, y));

But it behaves weirdly with diagonal movement? It's like it's trying to use a diagonal movement spritesheet.



Note that this ONLY happens when I use pathfinding. If I just use like, "Move Lower Right" or "Move Lower Left", the sprite does not break.



Buut I really need pathfinding, if I plan on not going insane! Sooo any suggestions?
I guess that plugin makes findDirectionTo return diagonal directions (1, 3, 7, 9). If there are no diagonal sprites implemented then a diagonal facing direction will mess up the sprite frame coordinates, as seen in your first video.

May be worth trying something like this instead (untested):

const d = this.findDirectionTo(x, y); this.moveDiagonally(4 + (d-1)%3, d<4 ? 2 : d>6 ? 8 : 0);
I.e. determine the horizontal/vertical components from the "found" direction, and use those for diagonal movement.

[Edit: hold on, I've made a mistake in the horizontal component. Correcting...]
[Edit 2: OK I think that'll work?]
I guess that plugin makes findDirectionTo return diagonal directions (1, 3, 7, 9). If there are no diagonal sprites implemented then a diagonal facing direction will mess up the sprite frame coordinates, as seen in your first video.

May be worth trying something like this instead (untested):

const d = this.findDirectionTo(x, y); this.moveDiagonally(4 + (d-1)%3, d<4 ? 2 : d>6 ? 8 : 0);

I.e. determine the horizontal/vertical components from the "found" direction, and use those for diagonal movement.

[Edit: hold on, I've made a mistake in the horizontal component. Correcting...]
[Edit 2: OK I think that'll work?]
Aaand that works, perfectly, oh my god, thank you!!
You just saved me hours of painstaking manual movement setting
I guess that plugin makes findDirectionTo return diagonal directions (1, 3, 7, 9). If there are no diagonal sprites implemented then a diagonal facing direction will mess up the sprite frame coordinates, as seen in your first video.

May be worth trying something like this instead (untested):

const d = this.findDirectionTo(x, y); this.moveDiagonally(4 + (d-1)%3, d<4 ? 2 : d>6 ? 8 : 0);

I.e. determine the horizontal/vertical components from the "found" direction, and use those for diagonal movement.

[Edit: hold on, I've made a mistake in the horizontal component. Correcting...]
[Edit 2: OK I think that'll work?]

Hey there! Small update for anyone who may find this, since I got to playtest the code again. Turns out it wasn't perfect after all! Basically if the NPC walked up or down it looked good, but the moment I tried having em move diagonally, I realized no matter what they would not turn left or right, they'd walk left or right, while still facing up or down.

After a couple of hours of attempts (i am new to javascript, i basically had to study what every single block did), I finally figured out a solution by mixing the moveStraight with the moveDiagonally:

const d = this.findDirectionTo(x, y); if (d==2 || d==4 || d==6 || d==8) {this.moveStraight(d);} else this.moveDiagonally(4 + (d-1)%3, d<4 ? 2 : d>6 ? 8 : 0);

Then by combining it with another pathfinding i found on the forum (also made by you cae!), and plugging in variables to make it modular, I got this working:

const x = $gameVariables.value(), y = $gameVariables.value(); const d = this.findDirectionTo(x, y); if (!d || !this.canPass(this.x, this.y, d)) { this.forceMoveRoute({ list: [{ code: 0 }] }); this.setMovementSuccess(false); } else if (d==2 || d==4 || d==6 || d==8) {this.moveStraight(d);} else this.moveDiagonally(4 + (d-1)%3, d<4 ? 2 : d>6 ? 8 : 0);

I am very happy to have solved this, very very proud of myself for figuring it out, and also very tired
Having said that, do lemme know if it could be cleaned up further or written better. Like, is it okay to have 4 "||" in a row? Again thank you very much for this
Like, is it okay to have 4 "||" in a row?
Shouldn't be a problem - here is an alternative:

JavaScript:
const d = this.findDirectionTo(x, y);  [2, 4, 6, 8].includes(d) ? this.moveStraight(d) : this.moveDiagonally(4 + (d - 1) % 3, d < 4 ? 2 : d > 6 ? 8 : 0);

Also, whenever I have code that is long like this inside the move route, I make it into a function and put it inside a general plugin - makes it easier to reference in a script call, debug, use, optimize, etc.
Turns out it wasn't perfect after all! Basically if the NPC walked up or down it looked good, but the moment I tried having em move diagonally, I realized no matter what they would not turn left or right, they'd walk left or right, while still facing up or down.
Oh, I see! Yep, your fix looks OK to me~ 👋

Just to be clear, for this part to work you need to provide variable IDs:

const x = $gameVariables.value(), y = $gameVariables.value();
E.g. for variable IDs 15 & 16:

const x = $gameVariables.value(15), y = $gameVariables.value(16);
(I'm pretty sure you know that, but someone else might try to blindly copy it.)

Original thread: https://forums.rpgmakerweb.com/threads/pathfinding-breaks-the-sprites-with-dot-movement.174362/