3
\$\begingroup\$

I'm looking to use A* Path-finding as a method of navigating my game terrain. Trouble is, my terrain is built upon play using a script and A* grid does not detect this, therefore marking all nodes as "un-walkable".

I'm wondering if anyone knows a solution for this or an alternative path finding method. I have tried enabling the terrain to spawn on edit more using ExexcuteInEditMode, but this does not seem to work either.

The terrain was generated through a fantastic guide called Procedural Terrain Tutorial.

Would greatly appreciate any help I'll be able to get.

I've attached some screenshots for clarity :

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I assume that you use collision detection to find out whether the target node is unwalkable. You can set collision matrix to make nodes ignore the terrain, so it can only collide with characters. \$\endgroup\$ – Alican Jul 30 '14 at 15:56
  • \$\begingroup\$ Obviously generating the A* grid before the terrain is generated doesn't work, so is there a reason you can't generate the A* grid after the terrain script has run? I don't quite understand the problem you are having... \$\endgroup\$ – jhocking Jul 30 '14 at 16:09
1
\$\begingroup\$

Based on your picture and your other questions you are using the Arongranberg A* Pathfinding Project.

First, be sure that in your Grid, the layer of the Playground is selected in your Mask. In your example this means that the Playground is in the layer Ground.

Second, use Update-Graph over every generated area (that means you create area, then you update the graph). If you add any obstacles after that, you have to update the graph again (or add obstacles before Graph-Update).

Additional note: You use a grid-graph, but your field seems to be made up of hexagons. You may use a point-graph with the points beeing located in the center of the hexagons. But I'm making assumptions about your game here.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Once your terrain is built start by manually turning down booleans for unwalkable nodes to walkable, You may think this as a forced method, but you need to assign

bool isWalkable(node){if isRight || isLeft ==NULL{
//# manual declaration of boundary nodes to unwalkable nodes, and when script starts,
//have start and end on boundary reinitialized to walkable, hence charachter can stand.
/*code here*/ 
}}

So that all values lying at the edge of the terrain grid are neutralised, and all values inside will be determined by A* script which is followed after this step, if your start and end are nonwalkable at start, after A* pathfinding , they have to be walkable for algo to start, which is then followed by UV Mapping which can invoke and take care of these calls

  • containsPoint (Vector a, Vector b, Vector c, Vector p);
  • DistanceSegmentSegment3D (Vector s1, Vector e1, Vector s2, Vector e2)
  • static Vector3[] ConvexHull (Vector3[] points) And if you think that the above code will work just once, add it in update method and try catch it by throwing new exception on selfupdate, whenever it is called again.

Hope this helps...

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.