- Home /
Ai pathing through a maze
I was wondering if anyone knows the best way to path an enemy through a maze to find the player. I can easily make the enemies walk towards the character when in range but they will get caught up against the walls. Any way to draw a path leading the shortest distance through the maze to the character that the enemy can follow?
This is achieved via unities built in pathfinding: http://www.youtube.com/watch?v=$$anonymous$$YRl4D-jTsY
Griffo has linked a page about it.
Answer by sparkzbarca · Aug 20, 2012 at 05:35 AM
the simplest is probably what is known as A* algorithm. Basically you divide the map into a grid and move from one square in the grid to the next.
If your wanting to learn programming writing a simple AI pathfinding program yourself is an excellent way to learn. If your good at it already and simply want pathfinding you can get versions of it off the asset store (not sure if there is a free version)
if you want to implement your own (takes some time certainly)
http://www.policyalmanac.org/games/aStarTutorial.htm is a good start to understanding how pathfinding is done.
Answer by Eric5h5 · Aug 20, 2012 at 03:57 AM
See here for one possibility. It uses an array to represent the world and a flood-fill algorithm for pathfinding.
Yes, even if the maze is "3D" it's likely to be really 2D, just presented in 3D. If it's real 3D, you're probably better off with some other technique.
I would rather not use an array for this. Pretty much just want to create a path around objects from one location to another.
You have to use an array of some kind, even if you use some other algorithm like A*. The "just creating a path around objects" part involves arrays no matter what.
Ya I guess you're right. Just have to figure out how to create a group of locations that the enemies have to follow from point A to B without encountering walls. I do have a grid based spawning system but I don't currently keep track of each location with an array.
Answer by Griffo · Aug 20, 2012 at 06:51 AM
What about this ..
http://docs.unity3d.com/Documentation/Manual/NavmeshandPathfinding.html
Your answer
Follow this Question
Related Questions
Visible GameObjects for AI 0 Answers
Follow up to AI Pathfinding Question 0 Answers
How to forbid an NPC to move diagonally using Character Controller? 1 Answer
Shooting AI problem 2 Answers