How to let an event move 8 direction?

I wana set customize movement to a NPC, but I realized the NPC only move in 4 directions(UP DOWN LEFT RIGHT) when the NPC moves closer to player or away from the player.
Therefore, how to let an event move 8 direction in the'ENTIRE' event movement system (ex. move randomly, get closer to player, away from player )?
Thanks!👋
If you are using a move route, there are commands there to move diagonally.

If you are not using a move route and events won't move diagonally by default, you might be able to get a plugin that will let them move diagonally (see if you can find one that affects events and not just the player).

If you then want them to face diagonally as well, you will need new spritesheets for all your events (the generator won't create them) with 8 directions, and a plugin to use the spritesheet (making sure it also affects events and not just the player).
This Workaround could simulate the feature in a very smal scope.

Event1 = NPC (No Autonomous Moveroute) Trigger Action Button - Textbox: Hello World

Event2 = Scene Controlling Event for all Event ID Moveroutes on that Map ; Trigger Parallel
Eventcode:

Wait ~15 Frames
Control Variable1 = Random 1 to 9
If Var1 = 1 Move Lower Left (Mark Skip if Cannot Move)
If Var1 = 2 Move Down ...
If Var1 = 3 Move Lower Right
If Var1 = 4 ... left
If Var1 = 5 Do nothing (Insert Wait 30 to 60Frames)
If Var1 = 6 ...right
If Var1 = 7 ... upper left
If Var1 = 8 ...up
If Var1 = 9 ... Move Upper Right
end

Not tested, just Theory. This would give an Event a Random Moveroute with 8 Possible directions and a 9th case where it does nothing.
If you are using a move route, there are commands there to move diagonally.

If you are not using a move route and events won't move diagonally by default, you might be able to get a plugin that will let them move diagonally (see if you can find one that affects events and not just the player).

If you then want them to face diagonally as well, you will need new spritesheets for all your events (the generator won't create them) with 8 directions, and a plugin to use the spritesheet (making sure it also affects events and not just the player).
Thanks for the ideas,and no need to let events face diagonally as well, i want events to move diagonally by default(Random , closers to player, away from player).
Ahh....I found so many plugins that only make the player move 8 dirctions not the events.
This Workaround could simulate the feature in a very smal scope.

Event1 = NPC (No Autonomous Moveroute) Trigger Action Button - Textbox: Hello World

Event2 = Scene Controlling Event for all Event ID Moveroutes on that Map ; Trigger Parallel
Eventcode:

Wait ~15 Frames
Control Variable1 = Random 1 to 9
If Var1 = 1 Move Lower Left (Mark Skip if Cannot Move)
If Var1 = 2 Move Down ...
If Var1 = 3 Move Lower Right
If Var1 = 4 ... left
If Var1 = 5 Do nothing (Insert Wait 30 to 60Frames)
If Var1 = 6 ...right
If Var1 = 7 ... upper left
If Var1 = 8 ...up
If Var1 = 9 ... Move Upper Right
end

Not tested, just Theory. This would give an Event a Random Moveroute with 8 Possible directions and a 9th case where it does nothing.
Thanks for your idea, looks like the theory works. Not only under move randomly conidition, but also others(move toward player, away from player).
My coding skill is limited, I cannot let the 'ENTIRE' event movement system go 8 directions.
If you want a plugin solution...

Or what I use for my game...
If you want a plugin solution...

Or what I use for my game...
THANK YOU! Solved!
Excellent idea. I added a few refinements, because I found that the NPC (a dog, in my case) would flip from one direction to an opposite direction sometimes, which looked unrealistic. So I augmented your solution a bit.

First I put the directions in a circle, and numbered them from 0 to 7: 0=U, 1=UR, 2=R, 3=LR, 4=D, 5=LL, 6=L, 7=UL. I arbitrarily started with a direction of 0, since that is what my uninitialized Control Variable will be equal to. For each move, I set a three-element array to the last move - 1, modulo 8, the last move, and the last move + 1, modulo 8. I then get a random number between 0 and 2 and use that to get the next move from the array. This ensures that each move will not be too different from the previous one.

In order to encourage my dog to take a straighter path, I expanded my array to six elements: The first element is the last move - 1, modulo 8, elements 1 through 4 are the last move, and the last element is the last move + 1, modulo 8, and I use a random number between 0 and 5 to index into the array. This means that two-thirds of the time, the dog will try to continue in the same direction.

You need to adjust the wait in the loop to make the motion look realistic; I am still fine tuning that.

It is still nowhere as realistic as a real dog, but it is a lot closer then what I had before.

Thank you a bunch for the inspiration.

Lynn

P.S. Another approach I am considering for the future is defining a whole bunch of waypoints, randomly choosing one, and using pathfinding to get there. I don't know much about RPG Maker's pathfinding yet, but I have heard it leaves something to be desired. So maybe implementing Dijkstra's algorithm in JavaScript is the answer. A future enhancement would be to make some waypoints more desirable, like ones near food stands or garbage cans.

L

Original thread: https://forums.rpgmakerweb.com/threads/how-to-let-an-event-move-8-direction.125437/