Follower Distance

MechPen

Warper
Member
Joined
Nov 4, 2018
Messages
4
Reaction score
10
First Language
English
Primarily Uses
RMMV
Follower Space ver 1.1

by me, MechPen


Here's a quick and easy plugin to change how many tiles the party members follow behind the leader. You might need this if your character sprites are wider or longer than 1 tile. Make that pony RPG!

Feature

- Change the distance that party members follow behind the leader.


Screenshots
followerSpace.png


How to Use

Place the plugin in the 'plugins' folder as usual. Add it to the project using the Plugin Manager. Adjust the Follower Distance parameter to the number of tiles you'd like the followers to be behind the leader.



Script
Code:
//=============================================================================
// MechPen Plugins - Followers Follow Less Close.
// MechPen_FollowerSpace.js
//=============================================================================

//It's important that this goes before anything otehr plug-in that modifies:
// Game_Follower.updateMove();

var Imported = Imported || {};
Imported.MechPen_FollowerSpace = true;

var MechPen = MechPen || {};
MechPen.FollowerSpace = MechPen.FollowerSpace || {};
MechPen.FollowerSpace.version = 1.1;

//=============================================================================
/*:
* @plugindesc v1.1 Lets party followers lag a set number of tiles behind.
* Useful if your character sprites are large (or fat :P ).
* @author MechPen
*
* @param Follower Distance
* @desc How many tiles are between each character.
* Default: 1
* @default 1
*
* @help
* Be sure to put this plug-in above any other plug-in that
* modifies Game_Follower.updateMove(); or else that plug-in might not work.
*
* Also: You can't set Follower Distance less than 1. It would make no sense to stack
* the followers like that!
* version 1.1
* - Fixed bug with Gathering, if the player hadn't walked enough to fill out his last positions.
* version 1.0
* - Finished plugin!
*/
//=============================================================================

MechPen.Parameters = PluginManager.parameters('MechPen_FollowerSpace');
MechPen.Param = MechPen.Param || {};
MechPen.Param.FollowerSpaceDistance = Math.max((Number(MechPen.Parameters['Follower Distance']) || 1), 1);

//=============================================================================
// Game_Player
//=============================================================================
MechPen.FollowerSpace.Game_Player_initialize = Game_Player.prototype.initialize;
Game_Player.prototype.initialize = function() {
    MechPen.FollowerSpace.Game_Player_initialize.call(this);
    this._lastPositions = new Array();
};

MechPen.FollowerSpace.Game_Player_clearTransferInfo = Game_Player.prototype.clearTransferInfo;
Game_Player.prototype.clearTransferInfo = function() {
    MechPen.FollowerSpace.Game_Player_clearTransferInfo.call(this);
    this.clearLastPositions();
};

Game_Player.prototype.getLastPositions = function() {
    return this._lastPositions;
};

Game_Player.prototype.popLastPositions = function() {
    this._lastPositions.pop();
};

Game_Player.prototype.clearLastPositions = function() {
    this._lastPositions.length = 0;
};

Game_Player.prototype.repeatLastPositions = function() {
    var currentPosition = [this.x, this.y];
    this._lastPositions.unshift(currentPosition)
};

MechPen.FollowerSpace.Game_Player_moveStraight = Game_Player.prototype.moveStraight;
Game_Player.prototype.moveStraight = function(d) {
    MechPen.FollowerSpace.Game_Player_moveStraight.call(this, d);
    if (this.isMovementSucceeded()) {
        var currentPosition = [this.x, this.y];
        this._lastPositions.unshift(currentPosition);
    }
};

MechPen.FollowerSpace.Game_Player_moveDiagonally = Game_Player.prototype.moveDiagonally;
Game_Player.prototype.moveDiagonally = function(horz, vert) {
    MechPen.FollowerSpace.Game_Player_moveDiagonally.call(this, horz, vert);
    if (this.isMovementSucceeded()) {
        var currentPosition = [this.x, this.y];
        this._lastPositions.unshift(currentPosition);
    }
};

//=============================================================================
// Game_Follower
//=============================================================================
Game_Follower.prototype.chasePlayerAtDistance = function(character, distance) {
    var spacesAway = distance;
    var spaces = $gamePlayer.getLastPositions();
    if (spaces.length < spacesAway) { return; }
 
    var sx = this.deltaXFrom(spaces[spacesAway - 1][0]);
    var sy = this.deltaYFrom(spaces[spacesAway - 1][1]);
    //TODO: reoptimize.
    if (Math.abs(sx) > 0 && Math.abs(sy) > 0) {
        this.moveDiagonally(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2);
    } else if (Math.abs(sx) > 0) {
        this.moveStraight(sx > 0 ? 4 : 6);
    } else if (Math.abs(sy) > 0) {
        this.moveStraight(sy > 0 ? 8 : 2);
    }
    this.setMoveSpeed($gamePlayer.realMoveSpeed());
};


//=============================================================================
// Game_Followers
//=============================================================================
Game_Followers.prototype.updateMove = function() {
    var spacing = 0;
    for (var i = 0; i < this._data.length; i++) {
        var precedingCharacter = (i > 0 ? this._data[i - 1] : $gamePlayer);
        spacing += MechPen.Param.FollowerSpaceDistance;
        this._data[i].chasePlayerAtDistance(precedingCharacter, spacing);
    }
 
    if ($gamePlayer.getLastPositions().length - 1 > spacing * (this._data[this._data.length - 1]._memberIndex + 1))
    {
        $gamePlayer.popLastPositions();
    }
 
    if (this.areGathering())
    {
        $gamePlayer.repeatLastPositions();
    }
};

MechPen.FollowerSpace.Game_Followers_jumpAll = Game_Followers.prototype.jumpAll;
Game_Followers.prototype.jumpAll = function() {
    MechPen.FollowerSpace.Game_Followers_jumpAll.call(this);
    $gamePlayer.clearLastPositions();
};

Game_Followers.prototype.synchronize = function(x, y, d) {
    this.forEach(function(follower) {
        follower.locate(x, y);
        follower.setDirection(d);
    }, this);
};


Terms of Use
This work is licensed under the MIT license.
 

Attachments

Last edited:

Featherbrain

Villager
Member
Joined
Jan 12, 2020
Messages
18
Reaction score
10
First Language
English
Primarily Uses
RMMV
This is an awesome, much-needed plugin. Thanks!

It's a shot in the dark, but I have to ask: Any chance you might update this plugin to support a pixel movement mod like Analog Move? Analog Move is my favorite pixel movement plugin but lacks any parameters to control follower distance.

ETA: Nevermind, I figured out how to change follower distance in the Analog Move plugin myself. (It's shockingly easy.) FWIW, I posted it in the Analog Move thread here: https://forums.rpgmakerweb.com/index.php?threads/analog-move.49828/post-1066448

Anyway, great plugin!
 
Last edited:

Ascare

Villager
Member
Joined
Dec 14, 2017
Messages
9
Reaction score
5
First Language
German
Primarily Uses
RMMV
Good plugin! I'm using tall sprites (with 8 frames for each direction), they look better now with a distance of 2.
There is a visual bug though...when the player starts walking away, the followers start walking in place until the target distance is reached and then they start moving.
It would look better, if they would stand still first and start walking and moving when distance is met.
 

underkactus

Warper
Member
Joined
Jul 4, 2020
Messages
1
Reaction score
0
First Language
Spanish
Primarily Uses
RMMV
Thanks a lot!!
I really expected this plugin a long time ago,
thanks a lot again <3
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Besides my Might and Magic inspired project, I have always wanted to make a Fire Emblem-like game. Time is the culprit... Between life, composing music packs, and working on a game can it be done!? The tactical plugins for MV work quite well based on what I have tested.
Yaaay! My second public script is out and approved! A VX Ace Final Fantasy IX styled Throw Script!

I look forward to all the constructive feedback I get but most importantly I hope everyone who ends up using it enjoys!

Yaaaay! Making scripts is fun lol. :D
When you're lost out therrrrre and you're alllll alone, ahwahwah waitin, to carry you hooooommmme, uhhheverywhere you look! (someone hit me with those backing vocals)
X.X cant focus... too many thing want do... help!
Day 2 of teaching MV, student can move cat across the map.

Forum statistics

Threads
100,525
Messages
976,813
Members
132,080
Latest member
nwr
Top