Theo - Pathfinding and Event Chase Player

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
Pathfinding and Event Chase Player
Version 1.0b
Type : Field script
Introduction
This script simply for determine the shortest path from started from a character position to target coordinate.

Features :
  • Determine the shortest path
  • Chase the player in smarter way
Video Preview

Download link :
Click here
 
Last edited:

Sophism

Veteran
Veteran
Joined
Aug 1, 2014
Messages
36
Reaction score
6
First Language
English
Primarily Uses
OK! So I tested it out in my hedge maze, and the event was able to find a path almost perfectly most of the time.

However, in a couple of instances, despite using Ctrl to walk through a wall before it reached me, the event seemed to first go to my previous position before adjusting and finding a new path. After some time playing hide and seek, it just stopped moving altogether, although it took a couple of minutes for that to happen.

The event in question was set up to the highest frequency and moving at twice the regular player speed. Its move route was set up with a single goto_player script call and repeat action toggled on.

I'll test it out a bit more later, to see if I can reliably reproduce the event halting the pathfinding.
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
Did you put <chase player> comment in event?

It will acts like an autonomous movement. So you dont need to manually put move route

New path will be refreshed in once per second
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
811
First Language
Hungarian
Primarily Uses
RMVXA
This script is just simply perfect!


Now I can discard my long and tedious eventing and instead use a simple comment for my guards and monsters!


You just saved me hell of a lot time with this, thanks a lot!


I expected some FPS loss, especially with multiple chasing events, but to my surprise, there was no significant FPS loss. o.o


Extra thanks for this! :)
 

Sophism

Veteran
Veteran
Joined
Aug 1, 2014
Messages
36
Reaction score
6
First Language
English
Primarily Uses
Did you put <chase player> comment in event?

It will acts like an autonomous movement. So you dont need to manually put move route

New path will be refreshed in once per second
I hadn't tried <chase player> yet, sorry. The wording in the instructions seemed to imply it would force the player to chase after the event instead.

I have tried that now, and while it didn't lock up, what did happen was that whenever the event had to redo the path, (Such as when I ran through one of the maze walls with Ctrl.) it would drop FPS down from 60 to 10-15 for a few seconds, then stabilize until I did it again. This may be an issue with the size of the map I tested this on.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
I hadn't tried <chase player> yet, sorry. The wording in the instructions seemed to imply it would force the player to chase after the event instead.

I have tried that now, and while it didn't lock up, what did happen was that whenever the event had to redo the path, (Such as when I ran through one of the maze walls with Ctrl.) it would drop FPS down from 60 to 10-15 for a few seconds, then stabilize until I did it again. This may be an issue with the size of the map I tested this on.
The FPS drop is because the event didn't find your position which is your current position is in unpassable / can't be found. And the event forced to search around the whole map. So, the issue came from the CTRL / Debug Through
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
811
First Language
Hungarian
Primarily Uses
RMVXA
Ahoy, Theo!


I had a little fun with this script while I tried something out and I noticed something rather odd...


I had my event set up this way:


Page 1:


- Only set up some commands in the autonomous movement.


- The event moved left and right between 2 points in a straight line. I used your script calls to do this, one find_path(x,y) for each points.


Page 2:


- Requires self-switch 'A' to be turned ON.


- Contains only the <chase player> comment.


- Fixed auto-move route here.


The event's self switch 'A' is turned ON automatically when the player has been spotted (I use a proximity script for this with line of sight feature).


So, what should happen is, when the player did not alerted the guard, it moves left and right, patrolling the area. But when the player has been spotted, the guard will start to chase the player. This works perfectly fine.


When the player successfully managed to hide for a short time, the event's self-switch will be turned off. This initiates the find_path(x,y) auto-movement again for the guard, so no matter where the player lured the guard, it will return to it's original position. And this works well too.


But after the guard has arrived it's original position and moves to the 2nd point, the find_path(x,y) auto-move route fails. It will run another additional path before returning to the 1st spot again. This additional path seems to have a pattern, but maybe I was just watching the blasted guard too long. :D


I wonder what could cause this? I tried to figure it out, but nothing seemed off in the script for me.


It seems to me that somehow the last move route executed from the <chase player> page goes to the end of the first page's auto-move route.


Just wanted to report this odd behavior, hoping that you can fix it. *-*
 

Jeysonmcfly

Just a random Joe Schmoe
Veteran
Joined
Jan 17, 2014
Messages
54
Reaction score
15
First Language
English
Primarily Uses
I'm thinking of using this to create somewhat smarter AI for a warcraft 2 style RTS/ god/village simulation game. the idea is that the player controls things via a cursor and can select characters then order them to do things. since the cursor would function as the player character, would it be possible for the NPC to go to a specific player-specified coordinate instead of just where the player is with this script?
 

Sausage_Boi

Game Dev. "Artist."
Veteran
Joined
Sep 10, 2014
Messages
1,737
Reaction score
676
First Language
Americanese
Primarily Uses
RMVXA
Does this script have the ability to send NPCs to a location based on Variables?
I.E. If I use a parallel process to store player X,Y in a variable, is there any method to call that information and use it to move the NPC to those coordinates?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
811
First Language
Hungarian
Primarily Uses
RMVXA
You would use:


find_path($game_player.x,$game_player.y)


No variables, no needless parallel process events, especially no parallel process events which update a variable all the time.


You use this in a "Set Move Route" script call, not with a simple script call command, so the target of the script call will be set via that target selector thing at the top left corner of the popup window where you can select "This Event", "Player", or a specific event.


If you need to use variables for X and Y position, you use this:


find_path($game_variables[ID],$game_variables[ID])


But do not update any variables/switches/self-switches in any constantly updating parallel process event, that will drop the FPS, and it is not needed at all.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
Just realized I had a topic for this, so well there goes the update after 3 years! :D
All of you who are using this script should use this version onwards!

@Sixth sorry for VERY LATE REPLY. But I managed to squash game breaking bug because I unintentionally change the original move route instead of altering and copying it, that as the result the event behaviour becomes so odd. Maybe that is also why.
 

Cerveau

Villager
Member
Joined
Sep 16, 2015
Messages
26
Reaction score
6
First Language
Tagalog
Primarily Uses
Does event chase offscreen persist in the new update?

The last time I remember is that when the player outrun the chasing event lets say like 10 squares outside the monitor, the event halts the chase to dead stop but if player reenters event vicinity it will resume chasing.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
The new update only fixes the weird behavior on using find_path on event command move route, not autonomous movement. And it doesn't touch anything regarding the event chase itself, so maybe it still is.

Here is the thing. By default, all autonomous movement stops once the event is far away from screen. Which it can be considered as either bug or feature. But anyway, I might try to look at it tomorrow, and see if I could make the event chase keep persistent even if it went off screen.

Thanks for reporting though.
 

bigcalsworld

Veteran
Veteran
Joined
Jul 5, 2015
Messages
81
Reaction score
58
First Language
English
Primarily Uses
Hi. Great script! Tried a couple of similar ones and they didn't work, so seeing this one actually do what I wanted was awesome :D.

Buuuut... did you ever look into the events moving when off screen? Right now I'm using it for NPC's in villages going home at a certain time, but of course they only move if I'm on screen with them, which isn't ideal lol. :)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,439
Reaction score
6,255
First Language
Indonesian
Primarily Uses
RMVXA
Buuuut... did you ever look into the events moving when off screen? Right now I'm using it for NPC's in villages going home at a certain time, but of course they only move if I'm on screen with them, which isn't ideal lol. :)
This is an intended design from the RM itself. And it has nothing to do with my script.
If you insist to make the event movement's keep being updated, try this patch. I'm not responsible for whatever lags you're encountering.
Code:
class Game_Event
  def near_the_screen?(*args)
    return true
  end
end
 

kuzai

Rain
Member
Joined
Jul 27, 2015
Messages
19
Reaction score
1
First Language
English
Primarily Uses
RMMV
EDIT: nevermind I misread.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

is there a script call that return how much turn has passed in battle?
Does anyone find this hard to read?

Enjoying my weekend at home to stay Covid free. How is everyone else doing?
If you enjoy speed mapping for RPG Maker MV check out my YouTube Channel. My latest video includes custom made tiles which makes a simple map look dynamic!

Check out my short game Hikari's World! : Chapter I, on itch.io/games.

Forum statistics

Threads
100,603
Messages
977,723
Members
132,213
Latest member
briggs_Boi
Top