Path finding issues

In the end what I want to do is what happens when you click on a spot in game and the heros run towards that spot. I haven't been able to figure that out. Here is what I have made so far.
screenshot_051022.jpg

code
$gamePlayer.setMoveSpeed(6); $gamePlayer.setMoveSpeed(4); var x = 18, y = 14; var d = $gamePlayer.findDirectionTo(x, y); if (!d || !$gamePlayer.isMovementSucceeded()) { $gamePlayer.forceMoveRoute({ list: [{ code: 0 }] }); $gamePlayer.setMovementSuccess(true); $gamePlayer._moveRouteIndex--; } else { $gamePlayer.moveStraight(d); } if(($gamePlayer.x ===x) && ($gamePlayer.y === y)) { this.command113(); }

It's not nearly fast enough and it gets very jarring. If the wait is lowered it gets even worse and the camera will give up on trying to show the player.

Thanks for any help.
I think you ignored a lot of the basics with that script.
And one of the basics is that an event is more than the contents - next time, please give the full event screenshot.
especially as your comment with the wait makes only sense if that content is executed as a parallel process, which is usually a bad idea for any form of moveroute.

because that is the second part of the basics you ignored:
a move route is always processed as an independent object in the game loop, and each event or player can only have one move route assigned at any one time.

so if you assign a second move route before the first move route is completed, the first move route gets deleted and replaced by the second one.
do that in a parallel process (or loop) and the first command of the move route gets repeated without the second command ever being processed. and it does not matter whether the move route is created by event command or by script command at that.


Two more basics:
why do you have the move speed set to 6, immediately followed by setting it to 4? the first command is completely useless at that.

and lastly to the way you present your issue:
Whenever you want help in sorting out strange behaviour of an event instead of a direct error message, we need to know both what you want to happen, and what really happens with the event you give the screenshot of.
and the first part is a bit basic in your description (the first two lines) while the second part is completely missing (you only say that it doesn't do what you want, not what it does, especially with or without waits.


That said, most people use a plugin for pathfinding exactly because of the timing issues when you try to do this with an event (and no, in this case timing refers to the overwriting of the move routes and not the speed of processing). Have you tried to use one of those plugins?
That is the whole event. I simply want the player to run towards the point in question and took everything else that could get in the way out of the equation. You can copy and past the script and make the event
in a new game with nothing else in it.

At the top of my post I said I wanted to do what happens in the game when you click on a square and the player runs there but have not figured it out fully.
Maybe this is too simple. But I think you just need to flag and follow.

Basically, you want a "Flag event" (could be invisible) as a parallel process that moves itself to wherever is clicked. This is easy to do.

Conditional Branch: Script: TouchInput.isPressed()
Code:
$gameMap._events[this._eventId].locate($gameMap.canvasToMapX(TouchInput.x), $gameMap.canvasToMapY(TouchInput.y))

So when the player touches the screen it moves this event to the Map Coordinates that the player touched. The .canvasToMapX() function is pretty handy.

So then it's just a matter of moving the player or NPCs or whatever toward that flag event.
I don't think they changed it yet, but basically the "Move Toward Player" route command use the
.moveTowardCharacter() function. It's ed in the true sense of the word. Because it's potential application is stunted, rigged, towards the Player only. You could/can use the function to route towards other events on the map. But only if you use the script call.
Within the event's move route window, you can use the script:
this.moveTowardsCharacter($gameMap._events[*whatever event Id here*])
So that event will continually move towards that flag event, wherever you place it.

[img]https://i.imgur.com/PSbYxrL.png[/img]
That is the whole event.
no, it is not.
your screenshot is missing the event properties like triggers, conditions and so on.

those parts are very important to understand what an event does, which is why I wrote that an event is more than its content alone.

and you never answered my other questions or say what happens if you follow my suggestions.

EDIT: the post above which was posted while I was writing shows a complete event with every property in the left half of the event window, that is what I meant.
It's a common event. I plan to use it more than once and was perfecting it in a controlled manner first. The event calling it is a blank event that is walked over. Nothing is set from this event.

What I want is for the player to run towards spot
x18,y14 which is done perfectly when you play in game and click on 18,14.
Actually, this "flag" event of mine doesn't need to be a parallel process.
The entire command could be refined as a script statement within the event's move route.
"repeat movements" is virtually the same as parallel process. Which means you can have the trigger set to something else, like Player Touch.
if(TouchInput.isPressed()){$gameMap._events[this._eventId].locate($gameMap.canvasToMapX(TouchInput.x), $gameMap.canvasToMapY(TouchInput.y))}

Although you might want to set the event's frequency to 'higher' or 'highest'. Using scripts in a move route means they don't run until the Event is ready to move. So loading into a map, there's always a little delay before 'lower' frequency events start following their move route commands.
It's a common event.
even a common event has properties - they are the settings above the content window in that case.
and if the common event is called, it takes on the properties of the calling event (even including access to the self-switches of the map event, or access to the troop info of the troop event that calls it.

and the behaviour of a loop is also dependent on whether the loop is inside a parallel process or an action button event.

and again you refused to answer my other questions, namely why you are setting the speed to six and then to four, and why you aren't using a pathfinding plugin.
Try using the Set Movement Route command to assign the player a repeating move route with a single move command:

const x = 18, y = 14; const d = this.findDirectionTo(x, y); if (!d || !this.canPass(this.x, this.y, d)) { this.forceMoveRoute({ list: [{ code: 0 }] }); this.setMovementSuccess(true); this._moveRouteIndex--; } else this.moveStraight(d);
A plugin would make this much easier, though. E.g. VisuStella MZ Events and Movement Core adds a Move To: x, y move route script:

Original thread: https://forums.rpgmakerweb.com/threads/path-finding-issues.147474/