MV - A "safe" way to increase jump duration & height?

● ARCHIVED · READ-ONLY
Started by EthanFox 6 posts View original ↗
  1. I've got a situation in-game where I want enemies, if struck by powerful attacks, to "jump".

    However, RPGM's default jump is pretty fast and low if only moving ~2 tiles, and it's very fast/low if I want the enemy just to jump straight up and come back down.

    I looked at something @caethyril mentioned in an old thread:

    Is there a way to change the jump speed?
    However, while this works, even a modest increase to the jump will cause events to jump in bizarre parabolas when over long distances (>20 tiles). Plus that's really about changing the jump speed (== duration) which is fine, but I also need to change the "height" the events reach.

    What I need, I think, is some sort of clamp which makes the small jumps higher & longer, while keeping the large jumps the same. I half-expected someone might've come up with this already, but I can't seem to find anything.

    Has anyone ever done this?
  2. To modify jump height, I think the easiest option would be to simply multiply the existing value, e.g.
    JavaScript:
    void (function(alias) {
      Game_CharacterBase.prototype.jumpHeight = function() {
        return 0.5 * alias.apply(this, arguments);  // multiply by 0.5
      };
    })(Game_CharacterBase.prototype.jumpHeight);
    technical notes + alternative
    By default the jump trajectory is parabolic (rpg_objects.js):
    JavaScript:
    Game_CharacterBase.prototype.jumpHeight = function() {
        return (this._jumpPeak * this._jumpPeak -
                Math.pow(Math.abs(this._jumpCount - this._jumpPeak), 2)) / 2;
    };
    The _jumpPeak value is defined when a jump starts (Game_CharacterBase#jump):
    JavaScript:
        this._jumpPeak = 10 + distance - this._moveSpeed;
        this._jumpCount = this._jumpPeak * 2;
    So I figure you can either modify jumpHeight or _jumpPeak. E.g.
    JavaScript:
    void (function(alias) {
      Game_CharacterBase.prototype.jump = function(xPlus, yPlus) {
        alias.apply(this, arguments);
        // make peak & duration independent of distance & move speed.
        this._jumpPeak = 10;
        this._jumpCount = 30;
      };
    })(Game_CharacterBase.prototype.jump);
    [Edit: to be clear, each of the snippets here that start with void are plugin code - you'd save the one you want as a .js file, then import it via the Plugin Manager.]
  3. Hi @caethyril , that's awesome - is there an easy way to modify it so I can address it in-game, to change it on-the-fly?

    The reason I ask is that I'm using SAN_AnalogMove, and one of the problems with that system is that it triggers PlayerTouch events the instant you touch the square of the event.

    So normally in MV, when you trigger a player touch event, you always know where the player will be standing because they finish their movement fully within the square.

    But SAN_AnalogMove allows the player to overlap the edge.

    A solution I've found is to command the player to do a 0,0 jump, and the player always seems to end the jump in the right place. Obviously though this is visually unattractive.

    What I'd like to do is

    1) Reduce jump height to zero
    2) Do the 0,0 jump
    3) Return jump height to the default

    Can this be done with that snippet?
  4. You could modify the plugin code to something like this (untested):
    JavaScript:
    void (function(alias) {
      var KEY = "_customJumpHeight";
      Game_CharacterBase.prototype.jumpHeight = function() {
        if (typeof this[KEY] === "number")
          return this[KEY];
        return 0.5 * alias.apply(this, arguments);  // multiply by 0.5
      };
    })(Game_CharacterBase.prototype.jumpHeight);
    Then you should be able to set a per-character _customJumpHeight value via Script command. E.g. in a move route, for the character being moved:
    • Set their jump height to 0:

      this._customJumpHeight = 0;
    • Reset their jump height to default:

      delete this._customJumpHeight;
    If you want to do this outside of a move route, you'll need to replace this in these 2 script calls with a valid character reference, e.g.

    $gamePlayer._customJumpHeight = 0; $gamePlayer.jump(0, 0); delete $gamePlayer._customJumpHeight;

    Edit - here's an alternative that, in theory, allows you to set a per-character jump height multiplier instead of an override value (also untested):
    alternative plugin code
    JavaScript:
    void (function(alias) {
      var KEY = "_customJumpHeightMult";
      Game_CharacterBase.prototype.jumpHeight = function() {
        var mult = typeof this[KEY] === "number" ? this[KEY] : 0.5;
        return mult * alias.apply(this, arguments);  // multiply by 0.5
      };
    })(Game_CharacterBase.prototype.jumpHeight);
    The only other difference is that the property here is named _customJumpHeightMult.
  5. Thanks @caethyril ! That worked perfectly. You're honestly amazing at this.
  6. :kaohi: Great, you're welcome! (I've had a lot of practice.)