Smart Pathfinding

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
Smart Pathfinding
2015.10.21
by Shaz
 
Introduction
This plugin allows you to set up smart pathfinding for events.
 
How to use
Add to your plugins folder (file name does not really matter, but I call mine SmartPath.js).  There are no parameters to set.
 
Use the plugin command SmartPath eventID1 eventID2 to make event 1 find a path to event 2
Use the plugin command SmartPath eventID x y to make the event find a path to x, y on the map
Use the plugin command SmartPath eventID cancel to cancel pathfinding for the event
 
eventID, eventID1 and eventID2 can be a number for a specific event (no leading zeros), 0 for the event issuing the plugin call, -1 for the player, or $gameVariables.value(id) to get the event number from the specified variable (replace id with the variable id, no leading zeros).
 
x and y can be map coordinates or $gameVariables.value(id) to get the x or y value from the specified variable (replace id with the variable id, no leading zeros).

The event will continue to follow its target until told to stop. So if the target is another event or the player, if the target moves, the event will adjust its course or follow, depending on how close it is to the target.
 
Plugin
Download from pastebin
 
Credit
- Shaz
 
Terms
- free for use in commercial games
 
Note
- the plugin says it works for events OR the player, but I'm not sure that it does work for the player.  I need to re-test that.
 
Last edited by a moderator:

Kane Hart

Elmlor.com
Veteran
Joined
Jun 27, 2014
Messages
656
Reaction score
166
First Language
English
Great Plugin Shaz. Thanks for putting them up on here.
 

Naoya

Warper
Member
Joined
Oct 19, 2015
Messages
3
Reaction score
0
First Language
Portuguese
I think I got a bug:

SyntaxError: Unexpected number

    at Game_Interpreter.command355 (rpg_objects.js:10436)

    at Game_Interpreter.executeCommand (rpg_objects.js:8894)

    at Game_Interpreter.update (rpg_objects.js:8802)

    at Game_Map.updateInterpreter (rpg_objects.js:6080)

    at Game_Map.update (rpg_objects.js:5987)

    at Scene_Map.updateMain (rpg_scenes.js:417)

    at Scene_Map.updateMainMultiply (rpg_scenes.js:409)

    at Scene_Map.update (rpg_scenes.js:398)

    at Function.SceneManager.updateScene (rpg_managers.js:1673)

    at Function.SceneManager.updateMain (rpg_managers.js:1641)

 

This happened whenever the script run (I tried putting the call on the movement of the event, and later tried to activate it on a On Key event. I tried the following script calls and all lead to the same error:

 

SmartPath 0 6

SmartPath 4 6

SmartPath 4 1 14

SmartPath 0 1 14
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
You're using Script Command.  You need to use Plugin Command.
 
Last edited by a moderator:

Naoya

Warper
Member
Joined
Oct 19, 2015
Messages
3
Reaction score
0
First Language
Portuguese
Woops, you are right :x Worked flawlessly now
 

dragoonkain

Villager
Member
Joined
Oct 17, 2015
Messages
20
Reaction score
16
First Language
English
This little plugin has made life so much better

I've made a couple of little tweaks I thought I would share in case they would come in handy for anyone. 

https://github.com/caseylutz/KCL-MV/blob/master/KCL_SmartPath.js

First off the ability to reference events by name. I actually created a separate module for this. It adds a findEvent call to the gameInterpeter to allow you to query events by numerical ID or canonical name. You can either include the FindEventsByName script and SmartPath by event names or  you can not include it and just use the numbers. This version of SmartPath will only use the additional script if it's present.

e.g.:

SmartPath Lab_001_Hero Lab_001_ExitSmartPath -1 Field_001_CenterSmartPath 3 7I also added a plugin call for waiting until the smart path is reached. 

SmartPath <event_target> WAITI also added an auto-cancelling trigger to clear the auto-path target once it's reached. This is useful if you are controlling the player and want to stop targeting at the end of the path. If you don't clear his target then he will constantly try to re-acquire it every time you move. 

SmartPath <event_target> AUTO_CANCELIf your target is actually impassible for whatever reason I've also added a cancellation near (so if you're within 1 tile...)

SmartPath <event_target> AUTO_CANCEL_NEARNow if you have an event where you want the hero to walk to a given location, wait on him, do a cutscene or whatever, and then resume play you can do that like so:

Plugin Command: SmartPath -1 Event_LocationPlugin Command: SmartPath -1 Auto_CancelPlugin Command: SmartPath -1 WaitYou can also have some actions take place before the Wait if, for instance, you'd like to have a conversation but make sure the event waits for the target to reach its destination.
 
Last edited by a moderator:

jamzkie143

CuteGranny
Member
Joined
Dec 7, 2014
Messages
21
Reaction score
12
First Language
English
Primarily Uses
N/A
how to edit event's direction where it is facing?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
does that question have anything to do with this plugin?
 

jamzkie143

CuteGranny
Member
Joined
Dec 7, 2014
Messages
21
Reaction score
12
First Language
English
Primarily Uses
N/A
does that question have anything to do with this plugin?
Hi Shaz, yes. Is there a way to change which direction the event/sprite is facing after it reaches its destination?  
 
Last edited by a moderator:

wizaerd

Adventurer
Member
Joined
Mar 13, 2012
Messages
219
Reaction score
26
First Language
English
Primarily Uses
You can use the Move Route command to turn or face a character in any position you want...  Doesn't necessarily need to be part of the plugin itself...
 

dragoonkain

Villager
Member
Joined
Oct 17, 2015
Messages
20
Reaction score
16
First Language
English
Hi Shaz, yes. Is there a way to change which direction the event/sprite is facing after it reaches its destination?  
You could potentially "wait" for the path-finding to finish and then issue a Move Route like wizaerd said. You'd have to "wait" long enough for the subject to find its target, cancel the smart-path and then set your direction. If you use the extensions I mentioned above you can alternatively use the plugin "WAIT" command to halt your event until the subject reaches the target, auto-cancel the smart path and then use move route (this prevents you from having to know exactly how many frames you need before you change direction). 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
You can add a loop that keeps checking to see if the event's x and y coordinates are where you want them to be - once they are, cancel the pathfinding and use a Set Move Route to make them face the direction you want.  Make sure your loop includes a Wait command so it can come up for air and let other things do their stuff.
 
  • Like
Reactions: Bex

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,699
Reaction score
1,893
First Language
Music
Primarily Uses
RMMV
Shaz, any plans on adding support for followers?  This would make things a lot easier for scripted scenes.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
The Ace scripts that did that ... what did they do when the cutscene was over and it was time for everyone to get back in line?
 

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,699
Reaction score
1,893
First Language
Music
Primarily Uses
RMMV
No, I mean as in having followers, at the start or during a scene (I guess my use of the word scripted was not a wise choice lol), move to various locations instead of using Move Routes with script calls to get them to go where you want during such a scene. Plus if you have the player talk to an NPC and you want followers to be at a very specific place, doing conditional branches to detect where the player is and move the followers accordingly would be tedious. I remember doing this in Ace and it was never fun. I had used Jet's Path Finding with a Follower Script (I believe Tsukihime's) to do what I needed to do. That's what I meant.
 

jamzkie143

CuteGranny
Member
Joined
Dec 7, 2014
Messages
21
Reaction score
12
First Language
English
Primarily Uses
N/A
You can use the Move Route command to turn or face a character in any position you want...  Doesn't necessarily need to be part of the plugin itself...
You could potentially "wait" for the path-finding to finish and then issue a Move Route like wizaerd said. You'd have to "wait" long enough for the subject to find its target, cancel the smart-path and then set your direction. If you use the extensions I mentioned above you can alternatively use the plugin "WAIT" command to halt your event until the subject reaches the target, auto-cancel the smart path and then use move route (this prevents you from having to know exactly how many frames you need before you change direction). 
You can add a loop that keeps checking to see if the event's x and y coordinates are where you want them to be - once they are, cancel the pathfinding and use a Set Move Route to make them face the direction you want.  Make sure your loop includes a Wait command so it can come up for air and let other things do their stuff.
Thank you very much for the help, everyone. 
 

dragoonkain

Villager
Member
Joined
Oct 17, 2015
Messages
20
Reaction score
16
First Language
English
No, I mean as in having followers, at the start or during a scene (I guess my use of the word scripted was not a wise choice lol), move to various locations instead of using Move Routes with script calls to get them to go where you want during such a scene. Plus if you have the player talk to an NPC and you want followers to be at a very specific place, doing conditional branches to detect where the player is and move the followers accordingly would be tedious. I remember doing this in Ace and it was never fun. I had used Jet's Path Finding with a Follower Script (I believe Tsukihime's) to do what I needed to do. That's what I meant.
I'm quickly running into the same desire myself in cut scenes where multiple people (events) are walking together. It's very tedious. I'm new to RM in general and find "Move Routes" to be very un-intuitive (I wish it let you draw paths visually). I may try to hit up the follower code over the weekend if nobody else tries to tackle it. 

The other major feature I could see being desirable here is a switch to A* or D*-style pathing. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,167
Reaction score
12,445
First Language
English
Primarily Uses
RMMV
No, I mean as in having followers, at the start or during a scene (I guess my use of the word scripted was not a wise choice lol), move to various locations instead of using Move Routes with script calls to get them to go where you want during such a scene. Plus if you have the player talk to an NPC and you want followers to be at a very specific place, doing conditional branches to detect where the player is and move the followers accordingly would be tedious. I remember doing this in Ace and it was never fun. I had used Jet's Path Finding with a Follower Script (I believe Tsukihime's) to do what I needed to do. That's what I meant.
I know what you mean - my question still stands.  For those Ace scripts that let you control the followers, what did they do (or what did you have to do) when the cutscene was over, to get everyone back where they should be?  I imagine you can't just walk off with your followers scattered all over the map - they don't just automatically go back into line, do they?
 

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,699
Reaction score
1,893
First Language
Music
Primarily Uses
RMMV
OH, I'm sorry.  My bad.  I didn't really see how you stated your question (was late night for me and I was derping lol).  Totally my bad.  Um, usually I'd just either have them get controlled via the pathfinding script to the main actor or, if they were clustered around the main actor, just use "Gather Followers".
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Potato The game! Few concepts for characters to my game.
Well, well, well, well....Lemme get a look at this fanart.
The Google Play rating for one of my games finally rose above 4.0 after getting review-bombed from a $0 sale. Now the game's sales are doing much better when discounted, so that's nice.
I'm getting close to releasing a demo. Working on formatting my Games in Development post.
I always see a few people asking for C# in next engine and I always thought: Do I not know enough about that language to tell it will affect extensibility and customizability to the negative? Watching a video from SumRndmDde today I feel confirmed.

Forum statistics

Threads
98,223
Messages
950,501
Members
129,522
Latest member
Rasenringu
Top