MV/MZ Tweaking walking animation.

When a character moves, it seems to stay on the middle frame (pattern 1) for the length of the animationWait before going to the next frame. As I am using HalfMove.js, the result is that often times taking just one step (i.o.w. a half-step) results in the character appearing to slide.

I want the switch from pattern 1 to pattern 2 to happen quicker at the start of walking, but am not sure how to go about this... any pointers welcome.
In the core scripts, map characters have a property named _animationCount to measure their pattern update intervals. A search of the MV/MZ core scripts (*_objects.js) for "_animationCount =" highlighted these Game_CharacterBase methods:
  1. initialize - when the character is first created.
  2. straighten - when the character starts jumping or is translocated.
  3. updateAnimation - when the pattern changes to the next frame.
For now let's focus on point 2. Point 1 may also be applicable: if so then that'll be easy enough to add in afterwards. 👋

Link to plugin for reference:
I did a quick search for _animationCount in that and found nothing. So I'll assume it's irrelevant~

As a first guess, I might try patching Game_CharacterBase#straighten. I figure you could reset the animation count to, say, half of animationWait? E.g.
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Shorter wait time for first map character stepping frame.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/178464/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (function(alias) {
  Game_CharacterBase.prototype.straighten = function() {
    alias.apply(this, arguments);
    this._animationCount = this.animationWait() >> 1;  // integer half
  };
})(Game_CharacterBase.prototype.straighten);
As mentioned, the initialize method can be patched with a similar block of code.

An alternative approach could be to (find an existing plugin to) increase the number of patterns (i.e. stepping frames), then override animationWait time as needed.
Thanks for the help! I added the snippet to the movement stuff plugin I am working on, and for some reason VisuMZ doesn't like what I did...

1750593509682.png

The error (on playtest start):
1750593541944.png


AFAICT VisuMZ_1_EventsMoveCore does not touch neither straighten nor animationWait, so not immediately sure what's happening. I am tweaking animationWait in said plugin I am working on, btw, but it shouldn't trigger the tweaked parts. Will do some digging.

EDIT: so it doesn't seem to like me calling animationWait() in the first place. Changing this to an integer value allows the game to load, although it doesn't seem to affect anything. More digging...

EDIT2: also tried to do the same in updatePattern() but again no cigar... _animationCount just won't budge 😴Will continue again tomorrow.

EDIT3: so interestingly, HalfMove.js doesn't reset _animationCount to 0 after each (half) step. Not really sure what is happening so am gonna ask Triacontane for advice, too.
for some reason VisuMZ doesn't like what I did...
From that error message, I guess VisuStella modify realMoveSpeed to check a property or something. Presumably they set up whatever-it-is (synchronised movement target?) in updateAnimation before calling animationWait.

A hacky workaround could be to put that in a try-catch and use a fixed value if it fails, e.g.
JavaScript:
try {
  this._animationCount = this.animationWait() >> 1;
} catch (ex) {
  this._animationCount = 7;
}

HalfMove.js doesn't reset _animationCount to 0 after each (half) step.
The core scripts don't reset _animationCount after each step, either. It's simply a counter for the frames between pattern update timings:
JavaScript:
Game_CharacterBase.prototype.animationWait = function() {
    return (9 - this.realMoveSpeed()) * 3;
};
I.e. if you move faster, you step faster. Compare with distance per frame:
JavaScript:
Game_CharacterBase.prototype.distancePerFrame = function() {
    return Math.pow(2, this.realMoveSpeed()) / 256;
};
I.e. frames per tile = 2 to the power of (8 - speed). As mentioned, you could override animationWait to reduce the pattern update interval, but then I imagine you'd want more than 3 stepping frames (a.k.a. patterns) to compensate.

The actual value of _animationCount doesn't matter unless it's in use. In other words, unless the character's pattern is heading towards an update (e.g. moving with walking animation enabled) then there's no point making any change to the counter.
A hacky workaround could be to put that in a try-catch and use a fixed value if it fails, e.g.
Even just having a fixed value doesn't make a difference. Naturally also tested with VizuMZ_1_EventsMoveCore disabled.
but then I imagine you'd want more than 3 stepping frames (a.k.a. patterns) to compensate.
Yes, changing the animationWait() plus changing the sprite sheet might be an option, but I was kind of hoping not having to go that route because then I'd have to have e.g. six-frame sprite sheets for all my sprites. Was hoping to get away with shortening the time it takes for the very first pattern change.

Hmmm... maybe I can half the animationWait and tweak the updatePattern() so that it it increments the patterns in fractions, or something:

JavaScript:
Game_CharacterBase.prototype.updatePattern = function() {
    if (!this.hasStepAnime() && this._stopCount > 0) {
        this.resetPattern();
    } else {
        this._internalPattern = (this._pattern + 0.5) % this.maxPattern();
        this._pattern = Math.ceil(this._internalPattern);
    }
};
Even just having a fixed value doesn't make a difference.
Yea, it was just a suggestion to avoid the error without unduly affecting the intent of the patch.

I wonder if it would work better to instead set a flag on the character when they're put in a new position, and halve animationWait while that flag is present? E.g. (untested):
Spoiler: plugin code v2
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Map characters: shorter wait time for first pattern update.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1519547/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (function() {
"use strict";
  const P = "_halfAnimWait";
  void (function(alias) {
    Game_CharacterBase.prototype.animationWait = function() {
      return alias.apply(this, arguments) / (P in this ? 2 : 1);
    };
  })(Game_CharacterBase.prototype.animationWait);
  void (function(alias) {
    Game_CharacterBase.prototype.straighten = function() {
      this[P] = true;  // half anim wait until further notice
      alias.apply(this, arguments);
    };
  })(Game_CharacterBase.prototype.straighten);
  void (function(alias) {
    Game_CharacterBase.prototype.updatePattern = function() {
      delete this[P];  // revert to normal anim wait
      alias.apply(this, arguments);
    };
  })(Game_CharacterBase.prototype.updatePattern);
})();
(That may well interfere with the VisuStella synced movement or whatever it is.)
I wonder if it would work better to instead set a flag on the character when they're put in a new position, and halve animationWait while that flag is present?
Yes, that's a step in the right direction, in that it works upon load!!!😂 Thank you! It doesn't seem to straighten() upon stopping to move, though. But I think I can set this[P] to true when the stopcount > 0 or something.

EDIT: resetPattern() seems appropriate... will do some testing.
EDIT2: seems to work! Many thanks!
JavaScript:
//=========================================
//Caethyril suggestion on how to tweak animationWait when idle
//=========================================
const P = "_halfAnimWait";
void (function(alias) {
    Game_CharacterBase.prototype.animationWait = function() {
        return alias.apply(this, arguments) / (P in this ? 2 : 1);
    };
})(Game_CharacterBase.prototype.animationWait);


void (function(alias) {
    Game_CharacterBase.prototype.resetPattern = function() {
        alias.apply(this, arguments);
        this[P] = true;  // half anim wait until further notice
    };
})(Game_CharacterBase.prototype.resetPattern)


void (function(alias) {
    Game_CharacterBase.prototype.updatePattern = function() {
        delete this[P];  // revert to normal anim wait
        alias.apply(this, arguments);
    };
})(Game_CharacterBase.prototype.updatePattern);
//=========================================
//Caethyril suggestion on how to tweak animationWait when idle
//=========================================
Great, you're welcome! 👋

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/tweaking-walking-animation.178464/