Event's becoming stuck when moving away from player

When I set an event’s autonomous movement type to move away from the player, even when set on “highest frequency”, if the event moves into a corner it will just stand there for 5 -13 seconds before turning. However oftentimes the direction it turns isn’t a direction it can move it so it will just stand for 5-13 seconds again before turning. This cycle repeats until it finally turns in a direction it can move and resumes fleeing the player.

Is there a way to have an event turn immediately if it runs into a corner while trying to move away from the player?

Issue.png
This little script should fix that 😀

Code:
class Game_Character < Game_CharacterBase    alias kmaf_move_away_from_character move_away_from_character    def move_away_from_character(character)    kmaf_move_away_from_character(character)    unless @move_succeed      dirs = [2,4,6,8]      sx = distance_x_from(character.x)      sy = distance_y_from(character.y)      if sx.abs > sy.abs        dirs.delete(sx > 0 ? 4 : 6)      elsif sy != 0        dirs.delete(sy > 0 ? 8 : 2)      end      move_straight(dirs[rand(3)])    end  end  end
First off thank you for your response, the script you provided helped them move much better.

                Although I noticed that if the event moves a certain distance away from the player it’ll start pacing pack and forth a few spaces regardless if it’s facing a direction it can move in. Although once the player starts to moves near it, it will (usually) stop pacing back and forth and resume normal movement. I think it might not be anything regarding your script; I’m not certain but I’m wondering if it’s caused by an event getting as far from the player as possible and not being able to move anywhere that’s “further” away. Regardless, since the game I’m going to make will have events stop moving from the player once the player is a distance away this probably won’t be a problem.

I also noticed that if an event moves in a single space that only has one exit then it’ll often start spinning nonstop even if they player is nowhere near it. I have no clue what’s causing that but it seems I can avoid this by making sure the map doesn’t have single spaces with multiple ways to move out so it's not a serious issue.

Again, thank you for your help.
Do you have anti-lag scripts? AFAIK most of those work by making some events stop doing things when not needed.
No I don't have any, but I will look into it. Thanks for the suggestion.
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.


at OP's request

Original thread: https://forums.rpgmakerweb.com/threads/events-becoming-stuck-when-moving-away-from-player.36327/