MZ Stop followers from inheriting realMoveSpeed from $gamePlayer

Wanting to make it look like characters walking up the stairs were actually making an effort, instead of just dashing through the stairs like it was flat terrain, I thought of tweaking the "stepping speed" and the "move speed" to respectively speed up and slow down when on a specific region.

This seems to work, but as soon as the leader has finished climbing the stairs and resumes its normal walking speed, the followers also pick up pace. The animationWait (i.e. the "stepping speed") is correctly dependent on whether the follower happens to be on the set of stairs or not.

Spoiler: The stub so far
JavaScript:
// ================================================== //
// RunUpTheStairs.js
// ================================================== //

/*:
 * @target MZ
 * @plugindesc Causes slower walkspeed while maintaining or increasing animation wait while on stairs
 * @author Werzaque
 * @url https://
 * @help Free to use and/or modify for any project, no credit required.
 *
 * @param RunUpRegion
 * @desc A region id that causes increase in stepping speed
 * @default 0
 * @type number
 *
 * @param RunUpStepping
 * @desc The increase in stepping speed. 1 is no change, 2 is double speed.
 * @min 0.1
 * @default 1.5
 * @type decimal
 *
 * @param RunUpSlowDown
 * @desc The decrease in move speed. 1 is no change, 2 is half speed.
 * @min 1
 * @default 1.5
 * @type decimal
 */

void (() => {
'use strict';

function toNumber(str, def) {
    return isNaN(str) ? def : +(str || def);
}
    const PLUGIN_NAME = "RunUpTheStairs";
    const parameters = PluginManager.parameters(PLUGIN_NAME);
    const pRunUpRegion = toNumber(parameters["RunUpRegion"]);
    const pRunUpStepping = toNumber(parameters["RunUpStepping"]);
    const pRunUpSlowDown = toNumber(parameters["RunUpSlowDown"]);

//increase stepping speed if on a "staircase" region
Game_CharacterBase.prototype.animationWait = function() {
    const isOnStairs = this.regionId() == pRunUpRegion && pRunUpRegion > 0 ? 3/pRunUpStepping : 3;
    return (9 - this.realMoveSpeed()) * isOnStairs;
};

//decrease walking speed if on a "staircase" region
Game_CharacterBase.prototype.realMoveSpeed = function() {
    const isOnStairs = this.regionId() == pRunUpRegion && pRunUpRegion > 0 ? 1-pRunUpSlowDown : 0;
    return this._moveSpeed + (this.isDashing() ? 1 : 0) + isOnStairs;
};
})();

I saw in rmmz_objects.js that Game_Follower.prototype.update and Game_Follower.prototype.chaseCharacter set the moveSpeed of the followers to that of the $gamePlayer, so I thought of tweaking that. After having no luck I was scratching my head and commented out the entire this.setMoveSpeed($gamePlayer.realMoveSpeed()); line in both functions, and interestingly enough it did absolutely nothing. So I'm a little lost as to how realMoveSpeed of the followers is set as it seems to match that of the $gamePlayer even without those lines. Any advice or pointers greatly appreciated.
Those 2 cases, update and chaseCharacter, are the only places in the core scripts where follower speeds are sync'ed.

Did you have any plugins active when you tested? Because if so, they can override the core scripts. That's one reason to make all core script "edits" via plugins, although really these sorts of things should be tested with a minimal setup.

This is actually a relatively tricky problem, since the existing follower chase code is designed for followers that move at the same speed as the player, and only when the player moves. Long story short, I think you'll need to rework the follower chase mechanic for this.
Spoiler: long story
We can start by saying "don't sync the move speed", e.g. by overriding the method with that line removed, or just resetting the speed after:
Spoiler: plugin code example
JavaScript:
;void (alias => {
    Game_Follower.prototype.update = function() {
        const v = this.moveSpeed();
        alias.apply(this, arguments);
        this.setMoveSpeed(v);
    };
})(Game_Follower.prototype.update);
void (alias => {
    Game_Follower.prototype.chaseCharacter = function() {
        const v = this.moveSpeed();
        alias.apply(this, arguments);
        this.setMoveSpeed(v);
    };
})(Game_Follower.prototype.chaseCharacter);
However, this exposes a different problem: followers moving slower than the player will try to chase again before they have stopped moving, causing a small "teleport" effect. This is because the moveStraight and moveDiagonally methods of Game_Player call _followers.updateMove().

"So," you may think, "why not just add an isMoving() check into chaseCharacter?" Well.
JavaScript:
void (alias => {
  Game_Follower.prototype.chaseCharacter = function() {
    if (!this.isMoving()) {
      const v = this.moveSpeed();
      alias.apply(this, arguments);
      this.setMoveSpeed(v);
    }
  };
})(Game_Follower.prototype.chaseCharacter);
This causes slower followers to be left behind. OK, so let's just call _followers.updateMove() every frame. But wait...that's exactly what Gather Followers does. 😩
Thanks a ton, will tweak and test it out tomorrow. And sorry for being unclear… when I said “commented out” I meant “overwrite the function with that line commented out”. I did test it with other plugins enabled though, since there were dependencies. Perhaps I may have missed an alias somewhere. In any case, many thanks for the pointers, will report back after I try some more.

EDIT: the followers being left behind (lagging behind) is actually something I want to accomplish. Ultimately I want them to make a little jog to catch up with the leader when the gap becomes too big. But… one thing at a time!
EDIT: the followers being left behind (lagging behind) is actually something I want to accomplish. Ultimately I want them to make a little jog to catch up with the leader when the gap becomes too big.
That does sound better than having them just stand there, menacingly.
Small update, it was VS Events and Movement Core that caused the tweaks to Game_Follower.prototype.update and Game_Follower.prototype.chaseCharacter to not do anything. I suspect it replaces these entirely with different functions so that the original ones are "ignored"?

The other movement related plugin, halfmove (triacontane), I can keep turned on. Choices choices.

EDIT: so issues aside (like having to fine-tune the distance between party members) it kind of works and any followers that were lagging behind will now walk back into line when the player stands still. As it is now, if the distance is too big the followers start floating through obstacles to reach the player. I don't suppose the solution for this is easy so perhaps if I really want "lively" followers the best way is to use events as followers instead...?



Sorry for the mess of a code, there's a lot of uneducated guesswork and trial and error going on...😔

Spoiler: The stub so far part two
JavaScript:
Game_Followers.prototype.update = function() {
// ================================================== //
// RunUpTheStairs.js
// ================================================== //

/*:
 * @target MZ
 * @plugindesc Causes slower walkspeed while maintaning animation wait while on stairs
 * @author Werzaque
 * @url https://
 * @help Free to use and/or modify for any project, no credit required.
 * 
 * @param RunUpRegion
 * @desc A region id that causes increase in stepping speed
 * @default 0
 * @type number
 *  
 * @param RunUpStepping
 * @desc The increase in stepping speed. 1 is no change, 2 is double speed.
 * @min 0.1
 * @default 1.5
 * @type decimal
 *  
 * @param RunUpSlowDown
 * @desc The decrease in move speed. 1 is no change, 2 is half speed.
 * @min 1
 * @default 1.5
 * @type decimal
 */

void (() => {
'use strict';

function toNumber(str, def) {
    return isNaN(str) ? def : +(str || def);
}
    const PLUGIN_NAME = "RunUpTheStairs";
    const parameters = PluginManager.parameters(PLUGIN_NAME);
    const pRunUpRegion = toNumber(parameters["RunUpRegion"]);
    const pRunUpStepping = toNumber(parameters["RunUpStepping"]);
    const pRunUpSlowDown = toNumber(parameters["RunUpSlowDown"]);

//increase stepping speed if on a "staircase" region
Game_CharacterBase.prototype.animationWait = function() {
    const isOnStairs = this.regionId() == pRunUpRegion && pRunUpRegion > 0 ? 3/pRunUpStepping : 3;
    return (9 - this.realMoveSpeed()) * isOnStairs;
};

//decrease walking speed if on a "staircase" region
Game_CharacterBase.prototype.realMoveSpeed = function() {
    const isOnStairs = this.regionId() == pRunUpRegion && pRunUpRegion > 0 ? 1-pRunUpSlowDown : 0;
    return this._moveSpeed + (this.isDashing() ? 1 : 0) + isOnStairs;
};

Game_Followers.prototype.update = function() {
    if (this.areGathering()) {
        if (!this.areMoving()) {
            this.updateMove();
        }
        if (this.areGathered()) {
            this._gathering = false;
        }
    }
    for (const follower of this._data) {
        follower.update();
    }
    if (!this.areMoving()) {
            this.updateMove();
    }
};
[/SPOILER]

void (alias => {
    Game_Follower.prototype.update = function() {
        const v = this.moveSpeed();
        alias.apply(this, arguments);
        this.setMoveSpeed(v);
        
        };
})(Game_Follower.prototype.update);
void (alias => {
    Game_Follower.prototype.chaseCharacter = function() {
        const v = this.moveSpeed();
        alias.apply(this, arguments);
        this.setMoveSpeed(v);
    };
})(Game_Follower.prototype.chaseCharacter);

})();

void (alias => {
  Game_Follower.prototype.chaseCharacter = function() {
    if (!this.isMoving()) {
      const v = this.moveSpeed();
      alias.apply(this, arguments);
      this.setMoveSpeed(v);
    }
  };
})(Game_Follower.prototype.chaseCharacter);
I notice the code you've posted has 2 chaseCharacter patches. The second one is just an enhanced version of the first, to prevent teleport-hops, so you should remove the first one:
JavaScript:
void (alias => {
    Game_Follower.prototype.chaseCharacter = function() {
        const v = this.moveSpeed();
        alias.apply(this, arguments);
        this.setMoveSpeed(v);
    };
})(Game_Follower.prototype.chaseCharacter);
Maybe just another typo from copying the code over, but I thought I'd mention it. 👋


Small update, it was VS Events and Movement Core that caused the tweaks to Game_Follower.prototype.update and Game_Follower.prototype.chaseCharacter to not do anything.
Ah, it looks like VisuStella's Events & Movement Core has plugin commands to change follower chase behaviour and/or manually move them around. So some compatibility issues would be expected.


JavaScript:
Game_Followers.prototype.update = function() {
// <snip> //
    if (!this.areMoving()) {
            this.updateMove();
    }
I see! With no other plugins, this just replicates the Gather Followers effect, i.e. when you stand still, the followers all move into the player's tile. Maybe that's what you want, though; it's certainly the simpler option.

You could rewrite it as a patch instead of an override, if you like. E.g. following the same pattern as the other patches:
JavaScript:
void (alias => {
  Game_Followers.prototype.update = function() {
    alias.apply(this, arguments);  // as usual
    if (!this.areMoving()) {
      this.updateMove();
    }
  };
})(Game_Followers.prototype.update);
That way, your plugin won't ignore changes made to this method by any plugin that loads before it.


As it is now, if the distance is too big the followers start floating through obstacles to reach the player.
That's because they're set to "Through: ON" in their initialize method. However, if they can't walk through walls then you'd want to change their chase behaviour: maybe use the built-in pathfinding, with an extra case to re-enable default chase mechanic if too far away. 😮‍💨

E.g. you could try replacing the update and chaseCharacter patches with something like this (untested):
Spoiler: revised code
JavaScript:
void (alias => {
  Game_Follower.prototype.update = function() {
    const v = this.moveSpeed();  // remember move speed
    alias.apply(this, arguments);  // update as usual
    this.setThrough($gamePlayer.isThrough());  // sync Through with player
    this.setMoveSpeed(v);  // reset move speed
  };
})(Game_Follower.prototype.update);

void (alias => {
  Game_Follower.prototype.chaseCharacter = function(character) {
    const v = this.moveSpeed();
    if (!this.isMoving()) {
      if ($gameMap.distance(this.x, this.y, character.x, character.y) > 6)
        alias.apply(this, arguments);  // chase as usual when too far away
      else   // otherwise use pathfinding
        this.moveStraight(this.findDirectionTo(character.x, character.y));
    }
    this.setMoveSpeed(v);
  };
})(Game_Follower.prototype.chaseCharacter);
(By default this won't pathfind diagonally, because neither moveStraight nor findDirectionTo consider diagonals. Plugins might change that.)
Thanks! Will try it out.
I notice the code you've posted has 2 chaseCharacter patches. The second one is just an enhanced version of the first, to prevent teleport-hops, so you should remove the first one:
Oh the sloppiness. I mean the second one is even outside the IIFE...
with an extra case to re-enable default chase mechanic if too far away.
Yes it would be cool if they teleported to the leader with a fade-in if they couldn't reach the leader in x seconds or so.
You're welcome!

I mean the second one is even outside the IIFE...
Just so you know, that doesn't actually make a difference, because the patch doesn't reference anything inside the "big" IIFE and is contained within its own IIFE.
JavaScript:
void (alias => {  // this is an IIFE, to allow reusing the variable name `alias`
  Some_Class.prototype.methodName = function() {
    // replacement method code here
  };
})(Some_Class.prototype.methodName);
That's actually one of my main reasons for writing patches like that: it makes it harder for people to accidentally put the code in a bad place. 😅


Yes it would be cool if they teleported to the leader with a fade-in if they couldn't reach the leader in x seconds or so.
Note that the core scripts don't have any premade character-fading code, so for that aspect you'd need some extra code to update character opacity when appropriate.
  • this.copyPosition($gamePlayer); puts this character on the player's tile, without fade.
  • this.isMovementSucceeded() returns whether the most recent move attempt was successful.
Good luck! 👋

Original thread: https://forums.rpgmakerweb.com/threads/stop-followers-from-inheriting-realmovespeed-from-gameplayer.167122/