![]() |
NPC Path-Finding Help
I've been working with a baddy and am trying to get him to move around something instead of continually trying to run that blocking tile over. I am not sure how it would be done so I am coming to forums for a little help. I have constructed small maze which is like 3 or 4 turns, and I would like the NPC to navigate through this small, not complicated "maze."
With that said, I don't want to program in level coordinates because I want the NPC to navigate by itself. I am just really unsure of how to approach this. I can only speculate that the NPC would need some sort of mapping function that would extend from the npc in all directions to allow it to correctly navigate the maze. Thanks For Any Help, It is Appreciated. |
Google A* and you can get an idea how to implement simple pathfinding. I believe there is already an example in the code gallery that is based on A* :o
|
Using A* for a maze is a good way to not get through the maze. A* uses a heuristic in the name of performance, and that heuristic doesn't know much about how to solve a maze.
Look up the "wall follower" rule if you want to solve a maze. Regardless, for any method, you will need to somehow read in the level tiles and convert that into a 2D array of paths and walls. Then on that array, you find the right path, and then convert the path back into directions to move the NPC. |
Ok, A* googled doesn't really give me anything related to scripting. Wall follower rule pulls up fine. My question now is how to read the in level tiles and convert to an array?
Awhile back I asked about a circle polygon type deal, and I was going to use the circle to make the array, but I am not sure how to get the level tiles into the array? My next question is, if this does work, how much lag would result from it? So, would it be possible for a server full of this type of npc to be walking around and not produce an enormous amount of lag? |
Here's how Zodiac's baddy movement works. It doesn't move directly to the player in one step but instead takes it in strides of 0.5 seconds of movement at max.
PHP Code:
|
Quote:
|
Quote:
Also I should note that you're venturing into an area that's more 'theory' than language-specific and your ability will require you to convert that theory into actual script. |
Before I do this I wanted to run it by someone and possibly get some feedback.
Could I set a group of variables up to check the tiles and then direct the npc to non-blocking tiles closest to its destination? It sounds possible, but it would be a lot of code and then some equations to determine which non-blocking tiles are closer to the npcs destination. Also is there a way to cycle through the variables to input them into the equation? (such as with a loop?) |
Quote:
If you are doing some other sort of path finding where you don't need to get to your destination, then A* is your best bet. |
use the built in findpathinarray() function
|
Quote:
Quote:
Thanks for your Help |
All times are GMT +2. The time now is 12:22 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.