- Home /
This question was
closed Oct 19, 2016 at 08:20 PM by
Alifar for the following reason:
The question is answered, right answer was accepted
Question by
Alifar · Oct 17, 2016 at 08:42 AM ·
pathfinding2d array
Pathfinding in 2d array of GameObjects
Hello, how can i to use pathfinding in 2d array of GO?
public GameObject tile;
public GameObject[,] tile_array;
public float gen_w;
public float gen_h;
public int MapW;
public int MapH;
void TileGen(){
for (int r = 0; r < MapW; r++) {
for (int c = 0; c < MapH; c++) {
float x = (r * (gen_w / 2)) / 100;
float y = (c * (gen_h / 2)) / 100;
tile_array[r,c] = (GameObject)Instantiate (tile, new Vector3 (x, y, 0), Quaternion.identity);
}
}
}
Comment
Best Answer
Answer by Zodiarc · Oct 17, 2016 at 08:57 AM
Use the A* algorithm https://en.wikipedia.org/wiki/A*_search_algorithm Here's an example implementation from when I had a small problem with it (Unityscript, but it's easy to translate to c# if needed) http://answers.unity3d.com/questions/749625/a-star-algorithm-produces-too-long-path-in-certain.html
Follow this Question
Related Questions
Path Finding using 2 dimensional array 1 Answer
Preventing lines from overlapping 1 Answer
A* Pathfinding, don't allow obstacle to block target. 1 Answer
PATHFINDING in a grid game 2 Answers