[XP] Lagless Path Finder

Started by Blizzard, February 09, 2013, 09:22:06 am

Previous topic - Next topic

Terv

August 19, 2013, 05:44:07 pm #40 Last Edit: August 20, 2013, 12:45:19 am by Terv
Where would I start editing if I want certain events' dyn_request update only, say, once per 40 frames? Because I have loads of NPCs that I do not need to find around new obstacles quickly. Having them stop for a second when the player blocks their path is even desirable so he can easily talk to them.

Blizzard

PathFinder#update, but it's simpler if you just change MAX_NODES_PER_FRAME. As a matter of fact, that should be enough since you can limit how many nodes are calculated every frame so there is no lag.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Terv

August 20, 2013, 05:33:49 am #42 Last Edit: August 20, 2013, 05:36:51 am by Terv
The problem with the max nodes is that the events will wait after every step instead of keeping walking. Basically they wait for their updated path and don't follow their old one until a new path is available. I guess so at least :^_^':
I'm currently using a loop with .find, followed by a wait of 40 frames. Does the job and costs around 0.5-1 fps per event in my usual use cases. Yet I'd like to know if there's a way with dyn_request.

Blizzard

Then no, at least not easily. That's not how they were intended to be used. You will have to modify the code yourself.
Keep in mind that the dyn_* variants are meant for targets that move and/or environments that keep changing.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Terv

August 20, 2013, 06:01:56 am #44 Last Edit: August 20, 2013, 06:07:40 am by Terv
Quote from: Blizzard on August 20, 2013, 05:44:57 amor environments that keep changing.
Good point, my towns aren't really ever-changing, at all. The loop now only issues a new find call if the event hasn't moved for a second. dynamic pathfinding or continuos updates in general is overkill for my scenario. Thanks for pointing that out.

hirasu

If i enable 8-Dir he stuck on the wall and can find the path and without 8-dir works im alone with this bug? when no please fix it :(

Blizzard

8-dir is not path finding using 8 directions, it's just used to cut corners in an 8-dir manner. It should actually work, though.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Heretic86

November 09, 2013, 10:31:57 pm #47 Last Edit: November 11, 2013, 07:55:09 am by Heretic86
Minor edit:

I'm trying a change to module PathFinder def self.update:

Spoiler: ShowHide
code removed, did not work as expected


Allows pathfind to a spot, wait, pathfind to next waypoint, wait, etc

---

I have an Event that changes pages, then tries to pathfind using Loose to a spot, but when it gets to the spot, it just goes back and forth on that spot but does not stop moving.  The pathfind is called in an Automated Move Route Script.

PathFinder.dyn_request(@id, [49,40], 2, true)

The spot is triggered when the player moves to that location so its occupied at the time of trigger.  There are terrain tiles in the way so it needs to pathfind to that spot, but once there, the NPC just moves back and forth and is stuck.  Anyone know what I'm doing wrong?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

maybe you need to add one more condition to stop the character when the character is already arrived at destination

something like :

if (last = characters.last) && last.x != @x && last.y != @y


or

if (last = characters.last) && (last.x - @x).abs < 1 && (last.y - @y).abs < 1

KK20

It's not just your edit; it's the script. Putting a RANGE of anything greater than 1 will cause this frantic walking of back and forth.

I made this change to Game_Character#update

 def update
   update_lagless_path_finder_later
   return if self.moving? || !self.has_path_target?
   if (@x - @path_targets[0].x).abs + (@y - @path_targets[0].y).abs <= @path_targets[0].range   #<===== THIS RIGHT HERE
     self.next_path_target
     check = true
   else
     check = @path_targets[0].dynamic
   end
   if check && self.has_path_target?
     if @path_targets[0].immediate
       PathFinder._find(self, @path_targets[0])
     else
       PathFinder._request(self, @path_targets[0])
     end
   end
 end

And that stopped it. The script was failing to remove the current path request and kept requesting paths constantly since the character will never reach the coordinates of the target location (and effectively call next_path_target). Not sure if confirmed, but just throwing this out there.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Blizzard

It's possible that I messed up during the refactor when I added waypoints. Let me know if this fixes the problem completely so that I can add it to the main script. Try both "passable" and "impassable" mode when you test this.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Heretic86

November 10, 2013, 08:27:20 pm #51 Last Edit: November 11, 2013, 07:59:24 am by Heretic86
Alright.  Further testing of checking for @wait_count didnt quite work, but lets see if this edit does anything.

Thank you guys.

---

After some decent testing, KK20's update appears to do the trick.  As a nice little benefit, this appears to also cause putting a wait command between pathfinding waypoints to work properly.

I did add in
|| self.jumping? 
in
return if 
also.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seltzer Cole

Please except my apologies for seeming like a complete newb, but I have no idea how scripts work. I am trying to create better pathfinding for the enemies in my game (abs style) so that when you come within a certain range of them, they automatically come at you to attack, or if you get a certain distance away, they stop.

I copied the script over into the proper spot, copied the following PathFinder.request(C_ID, TARGET[, RANGE[, PASSABLE]]) and pasted it into a script call in one of my events movements that is set to custom. I have tried plugging in multiple things within C_ID and Target etc... Nothing is working as it just keeps giving me a Syntax Error.

Basically, how exactly should PathFinder.request(C_ID, TARGET[, RANGE[, PASSABLE]]) be set up? I read through the script and read the tutorial but I find the technical terms used to be a bit confusing of what each of those 4 things mean.
You know you play video games to much when you put sunglasses on and whisper "Plus 10 Appearance"

If at first you don't succeed, call it version 1.0

Blizzard

December 01, 2013, 03:48:07 am #54 Last Edit: December 01, 2013, 03:49:14 am by Blizzard
C_ID, TARGET, RANGE and PASSABLE are the parameters of the call. This is standard call syntax notation and it means you can call it with either C_ID and TARGET or C_ID, TARGET and RANGE or with all 4 parameters. You are supposed to put actual values instead of literally PathFinder.request(C_ID, TARGET[, RANGE[, PASSABLE]]). I suggest that you download the demo and take a look how it's done there and it should become clear then.

All possible calls are:

PathFinder.request(C_ID, TARGET)
PathFinder.request(C_ID, TARGET, RANGE)
PathFinder.request(C_ID, TARGET, RANGE, PASSABLE)


C_ID is the "character ID". That means that if you put a 5 there, it will do path finding for the event with ID 5. TARGET is an array with the x and y coordinates like [10, 20]. RANGE is used if the character isn't supposed to go to an actual position, but just come into range of that position. e.g. if you put a 2 there, the character will move towards the target position and stop once he's 2 squares away. And PASSABLE is used for checking whether the target position has to be passable. e.g. You could gather characters around a tower with a certain range, but the tower is not passable so you have to use false in order to make the character stop when he's in range.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seltzer Cole

Quote from: Blizzard on December 01, 2013, 03:48:07 am
C_ID, TARGET, RANGE and PASSABLE are the parameters of the call. This is standard call syntax notation and it means you can call it with either C_ID and TARGET or C_ID, TARGET and RANGE or with all 4 parameters. You are supposed to put actual values instead of literally PathFinder.request(C_ID, TARGET[, RANGE[, PASSABLE]]). I suggest that you download the demo and take a look how it's done there and it should become clear then.

All possible calls are:

PathFinder.request(C_ID, TARGET)
PathFinder.request(C_ID, TARGET, RANGE)
PathFinder.request(C_ID, TARGET, RANGE, PASSABLE)


C_ID is the "character ID". That means that if you put a 5 there, it will do path finding for the event with ID 5. TARGET is an array with the x and y coordinates like [10, 20]. RANGE is used if the character isn't supposed to go to an actual position, but just come into range of that position. e.g. if you put a 2 there, the character will move towards the target position and stop once he's 2 squares away. And PASSABLE is used for checking whether the target position has to be passable. e.g. You could gather characters around a tower with a certain range, but the tower is not passable so you have to use false in order to make the character stop when he's in range.


Thanks for the quick reply. I will download the demo and test out what you said.
You know you play video games to much when you put sunglasses on and whisper "Plus 10 Appearance"

If at first you don't succeed, call it version 1.0

Seltzer Cole

Quote from: Blizzard on December 01, 2013, 03:48:07 am


Tried out the demo, finally got it working. But I have one small issue  :facepalm:

I am trying to make an event follow me or even just walk to my location by putting a 0 in the TARGET value (Which 0 is the player). Does this work because it just gives me a 359 error (Nil can't be forced into fixnum). The reason I got this pathfinder is so I could use it to give my evented enemies better AI when it comes to pathfinding when they chase you down to finally attack you. It works sending me or an event to locations I specify such as [11, 12] or whatever but it doesn't work trying to put a 0 in the TARGET value.

So basically, can this be used to send events my way or is the TARGET specifically for X and Y coordinates?

Thanks for you help.

EDIT: If it is possible, what exactly should I put in the TARGET value?
You know you play video games to much when you put sunglasses on and whisper "Plus 10 Appearance"

If at first you don't succeed, call it version 1.0

Blizzard

Use $game_player for TARGET, it should work.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seltzer Cole

Quote from: Blizzard on December 04, 2013, 02:34:21 am
Use $game_player for TARGET, it should work.


Works perfectly.

I am getting a few bugs however. I decided to go ahead with using dynfind since I will have multiple events moving about the map targeting you. The odd thing is that I noticed using "set move route" for any of the events and adding in a "wait" will mess up the script. Also I am currently getting strange things happening, such as the events will sometimes completely freeze or stop running certain variables or commands.

I am using PathFinder.dyn_find(7, $game_player, 1, false)

I have tried putting $game_map.events[7].clear_path_target in at several spots in an event page to stop the script to see if it would fix them from bugging but it does not.

I have my events set for custom move route "Move towards player" and have tried putting it on fixed but they end up just stopping at you or bugging worse.

Sorry to unload issues but I would like for this to work. Your script is almost to much of what I needed lol. It is an awesome script. All I am trying to obtain is for when the page is flipped in an event, they pursue you intelligently, and when I turned the switch off to flip the page back, they stop. =\

I will mess around with it some more because it might just be my own ignorance messing this up.
You know you play video games to much when you put sunglasses on and whisper "Plus 10 Appearance"

If at first you don't succeed, call it version 1.0

Blizzard

Can you make a demo?
Also, please check if the wait commands works when you don't use the path finder. Because the wait command is buggy in some RMXP editions.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.