Hello people.
I’ve downloaded the free version of the A* Pathfinding Project and I’m finding it hard to make a working grid graph to use in my game.
Basically, I’m generating a maze / dungeon using tile prefabs. I want to then create the grid after the generation of the level. I’ve managed to create the grid, re-size the nodes to the correct size and allign them correctly with the maze but I have a couple of questions regarding changing some of the functionality via C# script. Here is my current code:
// This holds all graph data
AstarData data = AstarPath.active.astarData;
// This creates a Grid Graph
GridGraph gridGraph = data.AddGraph(typeof(GridGraph)) as GridGraph;
// Setup a grid graph with some values
gridGraph.rotation.x = 90.0f;
gridGraph.center.x = ((x2 - x1) / 2) + x1;
gridGraph.center.y = ((y2 - y1) / 2) + y1;
gridGraph.cutCorners = false;
gridGraph.collision.use2D = true;
gridGraph.nodeSize = Tile.size;
gridGraph.width = Mathf.CeilToInt(Mathf.Abs(x2 - x1) * (1 / Tile.size));
gridGraph.depth = Mathf.CeilToInt(Mathf.Abs(y2 - y1) * (1 / Tile.size));
gridGraph.center = new Vector3 (gridGraph.center.x, gridGraph.center.y, 0);
// Updates internal size from the above values
gridGraph.UpdateSizeFromWidthDepth();
Here is the a dungeon and the dungeon with a grid generated that I did via the inspector in unity.
This doesn’t work in code because when the grid is in 2D it needs to use a sphere instead of a capsule, which I’m having rouble changing via script. How do you do that?
Also, this generation has a handy “unwalkable when no ground” tag which you cannot enable in 2d? I’m wondering if this is an oversight or something I have to put up with?
Finally, the grid is perfectly sized to the size of my tiles in the game, but as you can see, the corridors aren’t valid paths? Do I need to make the grid size smaller, or is there something I’m missing again?
Cheers for the help!
Tommy.