event approaching player

how can I make an event which will keep approaching the player but keep a distance apart?
for example the event will keep chasing the player but stop at 3 unit away
when player stop moving the event will also stop
You can make a conditional branch which checks the distance between player and the event (using variables to save the X,Y location of both) and issue the player approach only if its of a certain distance
I can't find this option inside the conditional branch
I have to do some coding on this?
You need to save each X,Y to a variable first then create a new variable which is equal to the difference between the locations, then you will check this variable on the conditional branch..

Or you can use the script conditional branch option and write the whole stuff as a line of code.
how can I get the location value of the player and the event?
how can I get the location value of the player and the event?
👋 Control Variables > Set > Game Data > Character > Player > Map X

Alternatively, if you're interested in a script solution:
Spoiler
Put this in a Script command in the event's move route (one command, set move route to repeat):
Code:
var D = 4; var d = $gameMap.distance($gamePlayer.x, $gamePlayer.y, this.x, this.y); if (d > D) this.moveTowardPlayer();
This says "target distance is 4; check distance between player and this event; if distance is more than target, move towards player". Distance is rectilinear, i.e. 1 tile diagonally is distance 2 (1 vertical, 1 horizontal). You can change the "D = 4" bit at the start to whatever distance you like. 🙏

For something more elaborate/stalkery, you could try this:
Code:
var D = 4; var d = $gameMap.distance($gamePlayer.x, $gamePlayer.y, this.x, this.y); this.setMoveSpeed($gamePlayer.realMoveSpeed()); if (d < D) this.moveAwayFromPlayer(); else if (d > D) this.moveTowardPlayer();
This one will match the event's speed to the player's, and make them move away if they're too close. For this one I'd recommend setting the event's move frequency to 5 (Highest), i.e. no pause between moves.
I put it in a spoiler because the variables approach is good practice if you're still learning. 😴
thank you very much!
yes I am starting to learn RMMV and have no knowledge about coding

Original thread: https://forums.rpgmakerweb.com/threads/event-approaching-player.110839/