Author Topic: Mimick pathfinding?  (Read 442 times)

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
Mimick pathfinding?
« on: January 02, 2013, 07:55:52 am »


               Is there any efficient way(you know better then the present pathfinding which is a lagfest if they get stuck somewhere) to have AI pathfind around impassable walkmeshes? At present I simply have my AI teleport according to the location they are trying to achieve, which works pretty well but players hate cheating AI that simply breaks the rules to cut corners.(for instance if the player runs up a staircase and the AI attempts to go straight to them through the WALL the AI will teleport right on top of the wall and reach the player almost instantly instead of traveling up the staircase). I wrote a BEAUTIFUL script to have AI avoid placeable obstacles and it works wonderfully. They see a placeable in there path and then travel in an angled direction to avoid the placeable just as a player would, but how can I get them to see an impassable terrain?
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Mimick pathfinding?
« Reply #1 on: January 02, 2013, 07:26:04 pm »


                How to see an impassable terrain?
I have not found an elegant way to do this. I did write a jumping AI however which is able to determine when an NPC is in combat and stuck. If they are stuck they are given the option to initiate another mode of movement (jumping, teleporting, fly, spider climb) and thereby cross whatever impassable terrain is in the way.

This is a very small piece of what you are trying to do. I don't have the answer for your pathfinding problem. I'll be watching to see what you come up with.
               
               

               
            

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
Mimick pathfinding?
« Reply #2 on: January 02, 2013, 07:51:26 pm »


               Wait so I'm actually touching on a ground no one has touched on before? Awesome! That's so rare in a game like nwn. That sounds fair to me, I'll break out the mountain dew and play my mortal kombat album and see if I can figure out how to resolve this issue.
               
               

               
            

Legacy_QlippothVI

  • Full Member
  • ***
  • Posts: 197
  • Karma: +0/-0
Mimick pathfinding?
« Reply #3 on: January 02, 2013, 08:45:41 pm »


               You might check out PK Busby's actingFenora, which adds Pathways to NPC Activities 6.1. This is effectively NPC Activities 6.2, and I will likely be posting a module illustrating how to use the Pathways addition to the Vault in the next week or so.

It effectively creates a series of line segments that you can designate as roads or paths that NPC will follow. And is very efficient, as pathing between two unobstructed points is quite easy for the engine. If you message me I can share what I have so far, it's a small module.
You can create a webwork of paths in your module and the scripting PK created will plot the course automatically. I'm hoping to create a multi-area module to illustrate this technology.

You can check out a small discussion on my form: http://qlippoth.dynd....php?f=18&t=195

You don't need to use it in every area; you can designate a creature to use Pathways, or an area where the creatures should use Pathways. It is VERY helpful for getting PCs to walk around tight obstacled areas, but does NOT function while PCs are in combat. So there are limits, since Pathways (or pathing, for that matter) is a non-combat mode of movement.

PK did a ton of cool things for NPC Activities and it's a shame it wasn't a clearly marketed update o NC Activities 6.1. PK wanted to do more, but then he fell off the face of the earth... I will likely add Lairs to that module example as well. That was something Deva wrote for me years back before PK took it onward. ':devil:'

- Qlippoth
               
               

               


                     Modifié par QlippothVI, 02 janvier 2013 - 08:49 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Mimick pathfinding?
« Reply #4 on: January 03, 2013, 12:29:09 am »


               <dropping...>

NPC Activities 6.1

QlippothVI's Forum

*interested*

<...a link or two>
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Mimick pathfinding?
« Reply #5 on: January 03, 2013, 02:13:18 am »


               Pathfinding has always been problematic in NwN.  At least they did a major overhaul of it and one point.  It was much worse before that patch.  I have zombies that will follow pc's across areas, but even they get stuck at a fence for instance.  Of course in this case it was intentional.  Though in some of my more creative efforts, a goblin masterscout followed me, in stealth into a shop and killed on of my pc's.So people are aware of this.  The specific instance of following up a staircase would probably be one of the most difficult.  The jumping thing is an ok though a rather heavy-handed method.  I use it for things like Yeti, or for flyers the disappear/appear, though I am aware of Npc's activites, I quickly made my own, and never went back to it after pathfinding was added.  Is that the best effort on this subject?  Problably just wondering.
I don't think they ever did a function to  pathfind specifically or determine whether a point was actually get too able. (Though your horse just shows up if it's nearby and can't get to you, i.e. it can't figure out how to get to you.  The default is for it to just jump to where you are).
The function: // FILE: x3_inc_horse       FUNCTION: HorseForceJump()
// This is used to make sure oJumper makes it to withing fRange of oDestination.
// The nTimeOut is used to set a maximum number of attempts that will be made.
void HorseForceJump(object oJumper,object oDestination,float fRange=4.0,int nTimeOut=10);

I know there is onblocked, and I use that for things like flyers who could fly over a bridge door or up to a higher level without using a ramp or some such method to arrive, though that does not address your  question.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Mimick pathfinding?
« Reply #6 on: January 03, 2013, 03:30:55 am »


               

Highv Priest wrote...

Wait so I'm actually touching on a ground no one has touched on before? Awesome! That's so rare in a game like nwn.


Not even remotely. Download the Omnibus and run some searches. This one is as old as NWN. Long story short, you need engine-level access to do anything other than jump-style solutions. See, e.g.:

NWN Omnibus/NWN Omnibus/data/BioWare Forums/Scripting/02601 I feel like I'm about to reinvent the wheel_ NPC Pathing & forcing 'unstick'.html
NWN Omnibus/NWN Omnibus/data/BioWare Forums/Archive Builders - NWN Custom Content/08058 More Pathnodes - Please_!.html
NWN Omnibus/NWN Omnibus/data/BioWare Forums/Scripting/07570 onblocked.html

Probably the worst part is that onblocked doesn't fire for placeables - only creatures and doors. This gave us no end of grief when trying to get critters to attack summoned-in player walls - we eventually had to resort to damaging all wall sections within a small radius of creatures onheartbeat.

Funky
               
               

               
            

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
Mimick pathfinding?
« Reply #7 on: January 03, 2013, 05:00:49 am »


               In terms of object creation what takes more resources? A blank item or a blank invisible creature?(no scripts on the creature) I figured out a system that works! '<img'>. The NPC creates a creature/item 10 meters in the direction they are heading towards. The engine won't let you place creatures or items outside of game physical boundaries(but sadly you can place a placeable outside of game boundaries so that doesn't work), that means you can determine a games boundaries based on whether the creature/item ended up where you intended it to go. Then make an angular offset to adjust for this. If it's a difference in the z axis that means it's either above/below the creatures current location and it stores a local location on itself to read the difference in it's position and the NPCs position as a difference in height is the issue. From there I'm working on having the NPC determine the "entrance" to reach this height.(on my server I'm using a waypoint flag at the ramp to let the NPC know, but I don't know if others would want to use this method). If it's a difference in x or y that means SOMETHING obstructed it(placeable, PC, wall, tile feature) and we can correctly infer that this is not a valid location to travel to and correct the NPCs path by having it avoid that particular spot(and I store it as a local location to avoid it needing to create items/invisible NPCs to read it again).

Although the imposed system is the public release, on my mod I actually decided to store local floats/waypoints in the area data where the NPC knows the boundaries by manual insertion rather then needing to create objects to set a path for it. For example I explained where the entrance to reach that particular height is with a waypoint(RAMP, TRANS, PLACE) and I have floats stored in the area painting a boundary of the game map in places the NPC would get stuck. The NPC then reads the x/y of it's path to know it's running into a wall.. Since my mod is only 300 areas in size it's an efficient method.(not all of them have ramps or blocking points)

I'm still heavily testing a lot of the code for it as it involves a lot of vectors, but I'll have something posted soon.

EDIT = I think I'll use a blank invisible NPC with an onblocked event. This allows me to alert the NPC if the obstructing object is a door or a PC in there path and adjust as necessary.
               
               

               


                     Modifié par Highv Priest, 03 janvier 2013 - 05:05 .
                     
                  


            

Legacy_CalSailX

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
Mimick pathfinding?
« Reply #8 on: January 03, 2013, 05:02:15 am »


               

Highv Priest wrote...

Wait so I'm actually touching on a ground no one has touched on before? Awesome! That's so rare in a game like nwn. That sounds fair to me, I'll break out the mountain dew and play my mortal kombat album and see if I can figure out how to resolve this issue.


 As some have already stated... we still fight with it.  Find an elegant way to deal with it, and even I will beat a path to the vault to have a look at your submission !

 My own project is using two different pathfinding modes that rely on having waypoints painted down in difficult areas for my ambient npc's to use.  Gets ugly, but you can burn a lot of cpu time before you start taking the hit that a single stuck npc generates.

 It's real crudge, that includes taking control of the ai level of npc's away from the engine. Needed for my project where npc's start to become ambient when a PC enters a connecting area... step in the door of the bar it's in party mode when you arrive.... sleepers aren't falling onto their bed as you come though the door. It's the little things like that drive me crazy. 

 Highv Priest it's a rabbit hole and once you poke your head into it, it's nothing if not a challange to get npc's to do the right thing "most of the time". 

Good Luck!

 
               
               

               


                     Modifié par CalSailX, 03 janvier 2013 - 05:03 .
                     
                  


            

Legacy_Highv Priest

  • Full Member
  • ***
  • Posts: 170
  • Karma: +0/-0
Mimick pathfinding?
« Reply #9 on: January 03, 2013, 12:52:50 pm »


               

CalSailX wrote...

 As some have already stated... we still fight with it.  Find an elegant way to deal with it, and even I will beat a path to the vault to have a look at your submission !

 My own project is using two different pathfinding modes that rely on having waypoints painted down in difficult areas for my ambient npc's to use.  Gets ugly, but you can burn a lot of cpu time before you start taking the hit that a single stuck npc generates.

 It's real crudge, that includes taking control of the ai level of npc's away from the engine. Needed for my project where npc's start to become ambient when a PC enters a connecting area... step in the door of the bar it's in party mode when you arrive.... sleepers aren't falling onto their bed as you come though the door. It's the little things like that drive me crazy. 

 Highv Priest it's a rabbit hole and once you poke your head into it, it's nothing if not a challange to get npc's to do the right thing "most of the time". 

Good Luck!

 


The way I'm doing it is basically like injecting code into the NPC. Using GetAttackTarget, GetAttemptedAttackTarget, GetAttemptedSpellTarget. The script reads those(using GetAttemptedAttackTarget first, GetAttackTarget second, and GetAttemptedSpellTarget last but I'm still testing this. I've had good results so far.) and then creates a path for the NPC just by creating a string of vectors checking all along the way if something obstructing is in the way(by either creating a blank invisible NPC or using my area data).  It only reads as fast as the NPC is moving and when an obstruction of a permanent nature is found I have the NPC setting the data normally manually put in as a local on the area.(making it similar to Get2DAString in that it might be expensive the first time because it has to create a blank object to essentially read boundaries, but it won't have to do it multiple times unless this player is doing everything they can to get the NPC stuck somewhere in different places and in that case you might need to make a rule). So far I've round the script needs to be called recursively only every 10 seconds for a hasted normal speed NPC, even less for a slow one, even less for a very slow one. Furthermore since it's checking if one of those attack declarations above is valid it makes it VERY efficient. The script cancels so quickly it uses virtually no CPU time.

Furthermore I added heuristics(sensitivity in cases of precision), you can specify how many vector points before it creates a blank NPC in it's path. By default it only creates them 10 spaces away(which is good enough to have the NPC act pretty intelligent and avoid most times as 10 spaces is effectively the range of a whole tile), but you can specify it to be every vector point(creating 10 blank NPCs altogether which is a bit much even if they don't have any scripts but OnBlocked) which is UNBELIEVABLY intelligent. It was freaking amazing watching the NPC chasing me and I run up the ramp to confuse him and he just promptly ran right around it to me(and killed me, forgot dm_god sadly).

I'll do everything I can to make it efficient AND effective to the point it is definitely worth it.

P.S= It's amazing what 4 cans of moutain dew and the mortal kombat theme song can do.

EDIT = Can the creatures exact action be called from GetLastAttackType without the creature actually performing the action? I'm trying to consider if this would work in this circumstance.
~~~~Highv Priest
               
               

               


                     Modifié par Highv Priest, 03 janvier 2013 - 01:07 .
                     
                  


            

Legacy_Sir Adril

  • Jr. Member
  • **
  • Posts: 96
  • Karma: +0/-0
Mimick pathfinding?
« Reply #10 on: January 03, 2013, 02:00:52 pm »


               Wow, that's some cool stuff. I'm still new to this NWN scripting malarkey, but in programming terms, that's actually a really neat solution to a big problem, and there's probably some uses for it outside of the original plan. '<img'>

Alas, using that system, when you've got all the bugs worked out, I'll no longer be able to use some of my tricks to survival when I low-level a normally mid-level or higher adventure. Time to figure out some new tricks '<img'>
               
               

               


                     Modifié par Sir Adril, 03 janvier 2013 - 02:03 .
                     
                  


            

Legacy_CalSailX

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
Mimick pathfinding?
« Reply #11 on: January 03, 2013, 09:50:55 pm »


               Highv Priest you can bet I'll have an eye on this thread.

My smart npc's still get utterly stupid if you trigger them into Combat Mode. Using the hooks might just give them brains enough to put up a good fight.... getting killed by something you shouldn't have picked a fight with is a plus.

I'm fair though... I sure that given enough time a member of some npc faction will decide to "Raise Dead" your looted corpse if only to exact a favor in return. Laying dead in the grass for a few minutes will give the player time to think of the errors of their ways... evil chuckle.

With the hooks in Get*Target() functions something like your work should plug right in along side the rest of the stuff currently in their AI.

Watching with interest CalSailX
               
               

               
            

Legacy_QlippothVI

  • Full Member
  • ***
  • Posts: 197
  • Karma: +0/-0
Mimick pathfinding?
« Reply #12 on: January 26, 2014, 05:08:08 pm »


               Man, I'm sorry I didn't follow up on this thread... Any updates?

Also, strange fact:
1. If you try to path your PC to a location (clicking on the spot of ground as your destination) that is too far or too complex to get to, your character won't try to walk there (pathing failure in the engine after X segments or some multistep algo?).

2. Attempting to reach a creature will sometimes succeed, but not always.  And never if you're attempting to talk to the creature. This is why your PC won't walk around the darned counter to talk to the shop keeper 5 meters away, but the engine simpy tells you they are too far away to talk to.

3. BUT, if you click on a usable placeable you get crazy complex success (within limits)! WTH does that mean? I'm wondering if the walk to placeables code has a bug that doesn't cut off pathing clculations for placeables like for pathing to other objects...
Disclaimer: I have no idea what kind of strain on the CPU this method causes. I have not tested, only leveraged this fact when playing other modules when too lazy to manually click my way around.

Could this be used to fix pathing during combat for creatures? Pathways only handles pathing during non-combat mode. Also, the setup currently causes the creature to return to the last segment they were supposed to travel to instead of the next one. Maybe I need to fix it so it tries to determine which is closer, last destination, or the next one after that.
Or better yet, try to fix Pathways so it recalculates (GPS, "rerouting...") instead of going all the way out to the last destination segment end.

This would be for two reasons:
1. Returning to their last segment destination does not use pathways, if the chase or battle took the group too far away down a complex path, they don't use Pathways to get back! (Bug I guess)
2. This would cause the creature to handle 1 above, and also ensure the creatures are always moving forward (maybe, not sure) instead of walking all the way back to their last destination if it is far behind them.

I'll need to throroughly test this hypothesis.

ANYway, could you "clear all" on the creature, plot the path to a placeable (you script in), then do so again for your PC (up until the distance to the transition is too far and you PC has simply "gotten away"? If they get close enough then direct the creature to attack the PC (or whatever is there to be attacked).

I was thinking of using placeables to help the PC navigate to places that are easy to get to (they can see very clearly how to get there), but is tedious. Maybe place a bush or something in the area to help with this for ease of travel.

Of course, I'd also like to be able to script the PC to use Pathways and simply give the destination for the PC. This leaves hands free for RP while the PCs all walk together to their destination. Anyone know how to script PC movements? Just need ot know where to start.

 - Qlippoth:wizard:
               
               

               


                     Modifié par QlippothVI, 26 janvier 2014 - 05:25 .