- Home /
A* nodes in the basic version of unity.
Hi, I am learning my first algorithm(A*) and I am wondering how exactly to set up the grid in unity. I know the pro version has some kind of navmesh, but I don't have that. Would I just use squares and place them all over the map? That seems really inefficient though. What do you guys do? Sorry if this is a bit broad, thanks!
Answer by whydoidoit · Apr 14, 2013 at 09:08 PM
The three choices are really:
Waypoints - connect them together by raycasting to make a mesh of nodes or manually connect them
Pros: You get a level of control over where things are, you can minimise the number of connections and deal with special areas by manual connections. Best possible solution for dynamically created areas and levels.
Cons: Coverage can be incomplete, potentially more overlapping paths, manual labour involved. Can be many connections from a node, little extra data (like costs of movement apart from distance). Dynamic obstacle avoidance is potentially more tricky.
Grid - identify walkable cells
Pros: You get automatic recognition of the scene geography, connections between nodes are always 4 or 8. Works extremely well if you are going to use influence maps. Good for recognising areas of potential exposure to threats etc. Good for dynamic obstacles that block paths.
Cons: Potentially wasteful, more memory usage, takes time to construct - consider baking it. Paths need smoothing or look "steppy", potentially many more nodes. Paths always have to follow blocks so there's no built in shortcutting.
Navmesh - create areas of negative space (places where your character can move) by creating polygons that fill it.
Pros: best possible coverage, great opportunities for best path detection and least chance of agent convergence.
Cons: hard to build, dynamic obstacles can be a challenge, less information about costs apart from distance.Not suitable for dynamically created areas due to build time.
You can potentially create a better result by combining cells from a grid to make a poor mans navmesh while retaining some of the extra data.
I wrote an article on Unity Gems on A* path finding with the grid method. I frequently also use waypoints.
I am interested in the grid method. I have a few question though. I am also not sure which article is yours. Is it this one? http://unitygems.com/astar-1-journeys-start-single-step/ After you answer I will ask the other ones, thanks!
int width, height;
//Active map of the world
public GridCell[,] cells;
Is that in the GridCell class? I have never used classes before so I don't really know how they work.
Also what is the out hit in if(Physics.Raycast(currentPosition, -Vector3.up, out hit, bounds.size.y))
I am trying to convert this to JavaScript and am having a hard time because I don't know what some of the things are.
Yes that's a class - which works pretty similarly in Unity Script.
Your answer
Follow this Question
Related Questions
A* optimization and path help 0 Answers
How can I convert this script to automatic fire? 2 Answers
Find a path with specific steps (moves) on a grid 0 Answers
How do i check if all tagged objects are inactive? 2 Answers
Can I convert unityscript to boo? 0 Answers