Move Toward Player uses Pathfinding

About:
Change the behavior of the "move toward player" move route command to use pathfinding.

Preview:
Screenshot_757.jpg

movetowardplayer.gif


The code:
JavaScript:
Game_Character.prototype.moveTowardPlayer = function() {
    const d = this.findDirectionTo($gamePlayer.x, $gamePlayer.y)
    this.moveStraight(d);
};

Game_Event.prototype.searchLimit = function() {
    return 9999;
};

Terms of Use:
MIT
Definitely a necessary plugin! Thanks
Hey sorry for my n00b question.. but do you save this code as a .js file & then put it in your plugins folder?


edit: sorry, the answer to my own question is yes & this plugin works really really well.

thank you.

exactly what I was looking for my police chase system.
Just paste the code in a text file,save it and change the extension from .txt to js.
since this works so well (like really well)

are you able to make one that does the same with move away from player?
Unlike move toward the player, move away from the player does not have a destination. So that can't use pathfinding.
ah, I get you.

how about path finding to region?

sorry, but pathfinding this is so useful in my game.
alright man, I got a problem with this plugin.

for some reason although it was working really well on my inside map with a lot of stuff going on.

I started a new map & it causes some extreme lag on events when move towards character is working.

super sad because it works so well for pathfinding but I couldn't even have one NPC using it on my outside map. ;_;
alright man, I got a problem with this plugin.

for some reason although it was working really well on my inside map with a lot of stuff going on.

I started a new map & it causes some extreme lag on events when move towards character is working.

super sad because it works so well for pathfinding but I couldn't even have one NPC using it on my outside map. ;_;
Instead of using the plugin, try creating a parallel process on the map that uses the same code but called on each moving event rather than being part of the prototype, and put a 1-frame wait after it. See if that helps.
Pathfinding is expensive. If you use it in a bigger map (with a long path to the player) and also many events using the same move command, it will lag.
Awesome! Was gonna look for a system to improve the pathfinding for monster chases. You definitely made my life a lot easier sharing this. Thanks for your hard work, and I can't wait to test this out while setting up the prototype of my project! 😀
this also works as a script & seems to run much lighter since it's an actual RPG Maker script.

$gameMap._events[this._eventId].moveStraight($gameMap._events[this._eventId].findDirectionTo( $gamePlayer.x,$gamePlayer.y ));
this also works as a script & seems to run much lighter since it's an actual RPG Maker script.
The difference is that it will use the default search limit, which is 12. So if the path ended up being too long, they don't use a detour. Not because "it is an actual RPG Maker script".
Sorry bro, I really don't know what I'm talking about. I'm trying to wrap my head around this stuff & it's just making me depressed.
Awesome, thanks for sharing!

Original thread: https://forums.rpgmakerweb.com/threads/move-toward-player-uses-pathfinding.133709/