Problem about moving away from player

I'm making an event trying to get away from the player and every time it gets caught, it gets faster until it's on Speed 6 and Frequency 6. I'm using a parallax map and even used the Yanfly Region Restriction to prevent it from getting stuck in a corner. But the "move away from player" doesn't quite work as intended, even when in custom movement I put "move away from player" on loop. Maybe I should use a script or am I overlooking something?

7675757.PNG


Captura4.PNG
"Move away from Player" literally just tries to move away from the player. If you want to account for walls etc then you'll need it to search for a path around obstacles. That's called "pathfinding".

I posted some relevant plugin code here, in case you want to try it out:
Plaintext-to-plugin instructions:
  1. Copy + paste the code into a text editor (e.g. Notepad).
  2. File -> Save As:
    • File Type: All Files
    • Filename: whatever.js
    (This works because .js files are plaintext.)
  3. Import that file as a plugin.
  4. Save your project to apply Plugin Manager changes.
  5. Test!
"Move away from Player" literally just tries to move away from the player. If you want to account for walls etc then you'll need it to search for a path around obstacles. That's called "pathfinding".

I posted some relevant plugin code here, in case you want to try it out:
Plaintext-to-plugin instructions:
  1. Copy + paste the code into a text editor (e.g. Notepad).
  2. File -> Save As:
    • File Type: All Files
    • Filename: whatever.js
    (This works because .js files are plaintext.)
  3. Import that file as a plugin.
  4. Save your project to apply Plugin Manager changes.
  5. Test!

Alright, so I tried the script and even though the movement has improved, the npc doesn't move away from the player unless the player walks around the npc.
any event can only have a single move route assigned to it at any given time, but in your original screenshots you have used both methods to assign a move route - the set command and autonomous movement.
if you use both they overwrite each other without ever completing any one.

have you already corrected that or is it still messing up your path?

anyway, please show screenshots of what your current event/move routes do after the change so we can look for remaining problems it that.
Alright, so I tried the script and even though the movement has improved, the npc doesn't move away from the player unless the player walks around the npc.
OK, first: I didn't notice earlier, but like Andar said, if you change the event page then the autonomous route on the new page will replace any route you've given it via Set Movement Route. Page 3 of EV089 sets a move route, then sets the variable to 5, which I guess will make the event change page, so the Set Movement Route command does nothing. A couple of ideas:
  • Make a new event page specifically for "running away", and put the movement into that page's Custom autonomous move route? Or...
  • Use a single event page with Conditional Branch and Set Movement Route commands to handle all of its movement. (There is a move command to set the character's move speed.)


The post I linked before mentions 2 possible approaches:
  1. Use a Script command in the move route, instead of "Move away from Player".
  2. Replace the "Move away from Player" logic with pathfinding.
If you want to use option 2, make sure you have added this code to the end of the plugin:
JavaScript:
// Override - replace "Move Away" type movement.
Game_Character.prototype.moveAwayFromCharacter = function(character) {
  this.moveStraight(this.findDirectionAway(character.x, character.y));
};

This pathfinding logic might still fail in certain map layouts because of the search limit. (It's also possible that I made a mistake in my code!) So, as well as screenshots of your event pages, it could also help to see a screenshot of the place(s) where your events are getting "stuck".

Also, just as a quick reminder: by default events cannot move through other events unless at least one of them is marked "Through", either via the checkbox in the bottom-left of the event page, or from a "Through ON" command in a move route. It doesn't matter whether the event has no image, is Below characters, etc: if it's not marked "Through", it will block other events. This also applies to followers (player party members). Some plugins (YEP_CoreEngine?) might change this.
any event can only have a single move route assigned to it at any given time, but in your original screenshots you have used both methods to assign a move route - the set command and autonomous movement.
if you use both they overwrite each other without ever completing any one.

have you already corrected that or is it still messing up your path?

anyway, please show screenshots of what your current event/move routes do after the change so we can look for remaining problems it that.
Here, it moves away only when the player moves 1x1 closer instead of continuing to run away from the player.
rtwrwerewrewrewr (1) (2) (1) (1) (1) (1).gif
45435.gif
5656.gif

Tried to make the ghost's movements into a different parallel event, but the problem continues.
999.PNG


0000.PNG


OK, first: I didn't notice earlier, but like Andar said, if you change the event page then the autonomous route on the new page will replace any route you've given it via Set Movement Route. Page 3 of EV089 sets a move route, then sets the variable to 5, which I guess will make the event change page, so the Set Movement Route command does nothing. A couple of ideas:
  • Make a new event page specifically for "running away", and put the movement into that page's Custom autonomous move route? Or...
  • Use a single event page with Conditional Branch and Set Movement Route commands to handle all of its movement. (There is a move command to set the character's move speed.)


The post I linked before mentions 2 possible approaches:
  1. Use a Script command in the move route, instead of "Move away from Player".
  2. Replace the "Move away from Player" logic with pathfinding.
If you want to use option 2, make sure you have added this code to the end of the plugin:


This pathfinding logic might still fail in certain map layouts because of the search limit. (It's also possible that I made a mistake in my code!) So, as well as screenshots of your event pages, it could also help to see a screenshot of the place(s) where your events are getting "stuck".

Also, just as a quick reminder: by default events cannot move through other events unless at least one of them is marked "Through", either via the checkbox in the bottom-left of the event page, or from a "Through ON" command in a move route. It doesn't matter whether the event has no image, is Below characters, etc: if it's not marked "Through", it will block other events. This also applies to followers (player party members). Some plugins (YEP_CoreEngine?) might change this.
The first approach seems safer, but how do I activate the script command?

Actually I have the YEP Core Engine (mostly to change the screen to 1024x768)
Here, it moves away only when the player moves 1x1 closer instead of continuing to run away from the player.
That looks like a passability issue: it seems to avoid moving onto certain tiles. Are there events or blocking regions on those tiles?

The first approach seems safer, but how do I activate the script command?
In the move route, instead of Move away from Player, use:
  • Script: this.moveStraight(this.findDirectionAway($gamePlayer.x, $gamePlayer.y))
That looks like a passability issue: it seems to avoid moving onto certain tiles. Are there events or blocking regions on those tiles?


In the move route, instead of Move away from Player, use:
  • Script: this.moveStraight(this.findDirectionAway($gamePlayer.x, $gamePlayer.y))
Yes, I am using YEP Region Restrictions to avoid the ghost getting stuck in trees (3 is All Restrict, while 2 is NPC Restrict only)

EDIT: Used your script command and it works perfectly now. Thank you!
EDIT: Used your script command and it works perfectly now. Thank you!
Oh nice! You're welcome~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/problem-about-moving-away-from-player.182736/