MV Hime's Lock Facing Direction Fix?

Heya, all y'all.

Part of my game involves a custom plugin that creates a field of view. Events that are outside of this field of view fade out until they're invisible, while events that are inside fade in until fully opaque. Because of this, it's very useful QoL-wise to have a plugin such as Hime_LockFacingDirection.js

The important code for this plugin is very simple:

JavaScript:
(function ($) {

  $.params = PluginManager.parameters("HIME_LockFacingDirection");
  $.button = $.params["Lock Button"].toLowerCase().trim();
 
  var TH_GameCharacterBase_isDirectionFixed = Game_CharacterBase.prototype.isDirectionFixed;

  Game_CharacterBase.prototype.isDirectionFixed = function() {
    return TH_GameCharacterBase_isDirectionFixed.call(this) || this.isdirectionFixButtonPressed();
  };
 
  Game_CharacterBase.prototype.isdirectionFixButtonPressed = function() {
    return Input.isPressed($.button);
  };
})(TH.LockFaceDirection);

However, it's pretty clear that when you hold the button in question (default 'control'), not only does the player character fix its direction, but every single other event does as well. I've come up with a messy fix for this already just today by adding a conditional to isDirectionFixed which compares the coordinates to the player character's own:
JavaScript:
  Game_CharacterBase.prototype.isDirectionFixed = function() {
    return TH_GameCharacterBase_isDirectionFixed.call(this) || this.isdirectionFixButtonPressed();
  };
becomes:
JavaScript:
  Game_CharacterBase.prototype.isDirectionFixed = function() {
    let character = $gamePlayer || ''
    if (character != '' && this._realX == character._realX && this._realY == character._realY ){
      return TH_GameCharacterBase_isDirectionFixed.call(this) || this.isdirectionFixButtonPressed();  
    } else {
      return TH_GameCharacterBase_isDirectionFixed.call(this)
    } 
  };

This seems to work fine, and I also have an alternative that compares spritenames instead via the _characterName properties if I encounter any major bugs with this.


But I still feel like I should ask: Is there a better (or cleaner) way to do this? The fix in general, that is, not just my solution.
To affect only the player, replace the 3 instances of Game_CharacterBase with Game_Player.
Hmmm, check if they have some event stuff?

return TH_GameCharacterBase_isDirectionFixed.call(this) || this.isdirectionFixButtonPressed() && !this._eventId;

EDIT: Ninjad by a real programmer
Thanks for the responses!

To affect only the player, replace the 3 instances of Game_CharacterBase with Game_Player.
This works great on its own, however it creates an error with GALV_StationaryTurn on line 102:
JavaScript:
if (Imported.TH_LockFaceDirection) {
    Game_Player.prototype.isdirectionFixButtonPressed = function() {
        var pressing = Game_CharacterBase.prototype.isdirectionFixButtonPressed.call(this); //<----
        if (pressing) {
            this._turnPause = 0;
            this._stopCount = 0;
        };
        return pressing;
    };
};

And when Game_CharacterBase here is changed to Game_Player, it gives me the following error:

Maximum call stack size exceeded

referencing the same line and the line above it.
Hmmm, with Galv plugin active also, it seems to work for me if you just check for the && !this._eventId; without changing anything else.
Yep. That seems to work just fine.

I thought I tried it earlier and it was giving me errors, but I'd put it inside my own conditional instead of in the return statement. Whoops.

Thank you!
I see you've got it working, but just to mention it~

I believe you could edit these lines of Galv's plugin:
JavaScript:
if (Imported.TH_LockFaceDirection) {
    Game_Player.prototype.isdirectionFixButtonPressed = function() {
        var pressing = Game_CharacterBase.prototype.isdirectionFixButtonPressed.call(this); //<----
...into a method patch rather than an override, i.e.
JavaScript:
if (Imported.TH_LockFaceDirection) {
    var alias = Game_Player.prototype.isdirectionFixButtonPressed;  // store (inherited) method
    Game_Player.prototype.isdirectionFixButtonPressed = function() {
        var pressing = alias.apply(this, arguments);  // invoke stored method
I'd like to bring this one back up again, because there's another interesting problem I've encountered and I think it's relevant enough to this topic that I can stick it in one place. When I set up tiles with 4-way direction, it appears that you can't move into tiles that have opposite the direction you're *facing* blocked off.

So for example, if a tile has blocked Right passability, then if you use Lock Facing Direction to face Left while moving upwards, you can't move up that tile.

Is there a way to change the passability behavior without affecting the direction code in Lock Facing Direction? A number of my plugins (such as Shora's Lighting) use the direction component of movement to handle what they do.
A shot in the dark: maybe you have another plugin that patches moveStraight such that it conflicts in some way with Galv's Stationary Turn.

I suggest sharing screenshot(s) of your Plugin Manager so we can see all the plugins you're using (and their load order, which might be important).

Have you tried turning off some plugins and testing to see if you can narrow down the culprit(s)? Remember to save your project to apply Plugin Manager changes before testing!
Thanks for the hint! Unfortunately nothing after Galv's Stationary Turn modifies movestraight. I used a search on all of the other plugins. After that, I opened up a test project such that the only plugins in use were, in this order:

CommunityBasic.js
Hime_Lock_Facing_Direction.js (With the above fix in this thread)
Galv_PixelMove.js
Galv_StationaryTurn.js

I was actually mistaken about the issue. It turns out that passability is blocked if the direction you're facing (at all, not just if strafing) matches the direction that the tile blocks. So moving Left into a tile that has Left blocked, blocks you.

For example:
I cannot move up onto this tile while moving upwards.
1754163289661.png

After strafing up-right (or up-left) to get into the top tile, I cannot move left into this corner.
1754163322358.png


But by strafing backwards I can get into the corner just fine.
1754163464403.png


And so after playing around with the plugins, it appears that the culprit is Galv_PixelMove. Without it, I can move into those squares. With it and no other plugins, I get that issue. In the readme part it says the player is prevented from moving to the edges of the tiles, but clearly the player can't move into the tile at all.

I'm wondering whether it has something to do with Game_Player.prototype.canPassTile (line 590) or Game_Player.prototype.canPass (line 606)
Plugin link:
Based on the line numbers you've given, and the fact that canPassTile is never called in v1.5 of the plugin, I think you may be using an old version. Patch note from the plugin code:

// 2025-05-11 - Version 1.5 - fixed issue with directional passabile tiles
You might also want to check for updates to the other plugins you're using, just in case.

Otherwise, have you tried rearranging the load order to see if that helps? E.g.
  1. Galv_PixelMove
  2. Hime_LockFacingDirection
  3. Galv_StationaryTurn
My thinking here is that:
  • Pixel movement is a big change, so it should load first.
  • Stationary turn patches itself based on Hime's plugin having been loaded before it.
Thank you! That was exactly it: I hadn't updated. I picked it up before May, and it never struck me that it could've been updated so recently, given that it's an MV plugin.

That's on me for not giving GALV nearly enough credit.

I might also play with the order, but so far testing has shown that they work fine in that order.
You're welcome! And yes, if things seem OK with the current load order then I'd recommend leaving it as-is. 👋

Original thread: https://forums.rpgmakerweb.com/threads/himes-lock-facing-direction-fix.177690/