Making an Event move in sync with the Player

I've come across a slight eventing problem, where I'm trying to make an event in one area of a room move in sync with the player. So far my event is set as a parallel process with several conditional branches checking if the player is moving, followed by checking which direction they're facing.



This does give a basic effect for what I want, but I've noticed that it seems to be really finnicky when deciding that the player is 'moving', and sometimes the event will move an extra space compared to the player. Is there any way to fix this issue?

Thank you in advance for the help!
Another way to accomplish this effect is to make an autorun event to stop player control, then inside that event set it so button presses move the player and any other events. You'll also want to include a way to go to the menu (and running if it's not disabled).
Checking if the player is moving can be done using
Code:
$game_player.moving?
the problem about moving extra spaces can be solved using wait commands. I'd recommend doing something like this using a script call:
Code:
if $game_player.moving?
  $game_map.events[event_id].move_straight($game_player.direction)
  Fiber.yield while $game_player.moving?
end
#event_id is your event id without leading zeroes
#example: $game_map.events[2] is the event with id = 2
This prevent your event from running again before the player stops moving. It also moves your event in the same direction the player is facing (note that this WILL cause issues if you have an event moving the player backward so try to avoid backward steps). It has to be a parallel process.

This only works if you use a parallel process. If, as kirbwarrior said, you want to handle everything using an autorun event then you have to do it in a different way.

Spoiler: EDIT:
I am not sure about how the engine handles the moving? method if the player moves more than one step. If it doesn't return false for at least one frame after each step you can use this variant:
Code:
if $game_player.moving?
  $game_map.events[event_id].move_straight($game_player.direction)
  Fiber.yield while $game_map.events[event_id].moving?
end
If you use this be sure to set the same speed for both $game_player and the moving event (events are usually 2x slower than $game_player).
Spoiler: One little note:
This event moves your event in the direction the player is facing when moving. It does not move your event to follow the steps of $game_player. If you want to do something that follows it then you have to use a different method.
I did not Test your Eventcode OP, but the problem is your Wait commands and the hidden info that eventpages normaly dont reexecute every frame. But in your case it seems to be important that the player moving is detected fast to make sure the event is doing what he is suposed to do.
This can be achieved with a loop inside your paralell event.

Paralell Eventpage:
Insert following (pseudocode):

Loop
Your Eventcode
1Frame Wait (This makes sure we dont crash the game with an endless loop)
repeat above

Delete your 5 frames wait, its important that there is only this one 1 Frame Wait.

Edit:
Iam not sure if the branch for player moving is the best to use in your case,
it could be better to trigger if player pressed the direction key and than checking if the tile he wants to move to is passable. there are different ways, and iam sure that atleast half of em have some kind of bugs we cant think of yet, so experimenting time i would say. 🙂 therefor it would be realy helpfull to know what exactly is going on in that room.

Edit2:
Map Coordinates^^ Could be also used to solve this, but i dont have much time right now, sorry.
Thank you all for your help, I've got it working more or less how I want it!

Original thread: https://forums.rpgmakerweb.com/threads/making-an-event-move-in-sync-with-the-player.86549/