Issue with Moving an Event

I came across a YouTube tutorial by The Odie that was using this script call:

$gameMap._events[14].moveStraight($gameMap._events[14].findDirectionTo( $gamePlayer.x,$gamePlayer.y ));

to move an event toward a player (actually, to chase a player, but the desired outcome was still event --> player). I tried to implement it, but it isn't acting correctly. The setup is I have a character who is circling a sofa while the main character speaks with someone in the other room. That triggers a switch, and when the main character steps back into the living room, I have a script to trip that other character/event's self-switch A. That is when I'm trying to use this script to make that event walk to where my character is standing. I tried the script both as written, as well as swapping out the event number with the this_eventId used in the actual video because that made the game crash.

The issue is when the event starts to walk, it doesn't come the full way and/or skips awkwardly over the otherwise impassable sofa. I have also tried to simply event the movement rout to have the event move toward the player, but with the same issues.

Lastly, I tried the pathfinding script in the spreadsheet: this.moveStraight(this.findDirectionTo(X, Y)); and still didn't have any success.

What am I doing wrong?
$gameMap._events is an array holding all the events on a given map. Have you replaced the "14" from the video with the event ID of your event, cause otherwise it won't work
Yes, the 14 was for my event after replacing what the video had.
$gameMap._events is an array holding all the events on a given map. Have you replaced the "14" from the video with the event ID of your event, cause otherwise it won't work
please post screenshots of your events and their commands - we need to check what you have done to find any errors.
$gameMap._events[14].moveStraight($gameMap._events[14].findDirectionTo( $gamePlayer.x,$gamePlayer.y ));
This will move map event 14 by 1 tile along a passable path to the player's current position.

The issue is when the event starts to walk, it doesn't come the full way
moveStraight moves 1 tile. If you want to move multiple tiles, consider multiple move commands and/or a repeating move route.

and/or skips awkwardly over the otherwise impassable sofa.
This might be various things. It's not clear to me what "skip awkwardly" means. E.g.
  • Maybe the event is set to Through ON.
  • Maybe the sofa is unintentionally marked as passable, either in the tileset, or via a plugin feature.
  • If you're trying to string these together without a move route, the timing may be off: all movements technically happen instantly, but the sprite travels smoothly between tiles. A move route does not process the next command until the sprite has finished travelling.

Lastly, I tried the pathfinding script in the spreadsheet: this.moveStraight(this.findDirectionTo(X, Y)); and still didn't have any success.
As noted on that spreadsheet, this approach is for use in a move route. You need to replace X and Y with appropriate values, e.g.
JavaScript:
this.moveStraight(this.findDirectionTo($gamePlayer.x, $gamePlayer.y));
This will find a path to the player (using built-in pathfinding) then move the character 1 tile along that path. If you want them to constantly path to the player, just set the route to repeat.

Alternatively, that spreadsheet has a "Path to Tile" entry. As noted on the sheet, it is meant to be used as the only command in a repeating move route. It is for situations when you want the character to move all the way to the target (or as close as they can get), then stop.

[Edit - corrected a typo in my "replace X & Y" example: findDirection -> findDirectionTo.]
This will move map event 14 by 1 tile along a passable path to the player's current position.


moveStraight moves 1 tile. If you want to move multiple tiles, consider multiple move commands and/or a repeating move route.


This might be various things. It's not clear to me what "skip awkwardly" means. E.g.
  • Maybe the event is set to Through ON.
  • Maybe the sofa is unintentionally marked as passable, either in the tileset, or via a plugin feature.
  • If you're trying to string these together without a move route, the timing may be off: all movements technically happen instantly, but the sprite travels smoothly between tiles. A move route does not process the next command until the sprite has finished travelling.


As noted on that spreadsheet, this approach is for use in a move route. You need to replace X and Y with appropriate values, e.g.
JavaScript:
this.moveStraight(this.findDirection($gamePlayer.x, $gamePlayer.y));
This will find a path to the player (using built-in pathfinding) then move the character 1 tile along that path. If you want them to constantly path to the player, just set the route to repeat.

Alternatively, that spreadsheet has a "Path to Tile" entry. As noted on the sheet, it is meant to be used as the only command in a repeating move route. It is for situations when you want the character to move all the way to the target (or as close as they can get), then stop.
That got it! Thank you so much for your help.

Original thread: https://forums.rpgmakerweb.com/threads/issue-with-moving-an-event.162528/