Hi.. I've been testing NPCs' chasing around against obstacles such as doors and stairs.. is any method of smart chasing such as A*, considering statics and door supported by POL? I mean, is there any core feature that enables a NPC to find the best path, if there's one, to the target?
Thanks in advance!
Chasing AI
Moderator: POL Developer
Re: Chasing AI
Use FindPath()...
FindPath(npc.x, npc.y, npc.z, target.x, target.y, target.z, npc.realm, FP_IGNORE_DOORS);
something along that line... This returns an array of structs with each step the NPC must take along a path to get to the target so then you do a loop going through the entire array and doing WalkTowardLocation/RunTowardLocation for each step. The FP_IGNORE_DOORS ignores doors, you can also add in FP_IGNORE_MOBILES too to keep other PCs/NPCs that may be in the path from interrupting the path. But now when the NPC needs to walk through the door, you'll also have to script for it to open the door otherwise it will get hung up there but if the door is already open it won't interfere.
Documentation on FindPath() is here...
FindPath(npc.x, npc.y, npc.z, target.x, target.y, target.z, npc.realm, FP_IGNORE_DOORS);
something along that line... This returns an array of structs with each step the NPC must take along a path to get to the target so then you do a loop going through the entire array and doing WalkTowardLocation/RunTowardLocation for each step. The FP_IGNORE_DOORS ignores doors, you can also add in FP_IGNORE_MOBILES too to keep other PCs/NPCs that may be in the path from interrupting the path. But now when the NPC needs to walk through the door, you'll also have to script for it to open the door otherwise it will get hung up there but if the door is already open it won't interfere.
Documentation on FindPath() is here...