In this part I will show you how to set up the system in a new scene.
In the A* example project, create a new scene.
Then place a plane at position 0,0,0 with the scale 10,10,10.
Add a direction light to make it brighter.
Then you should create a new empty gameObject, name it “Walls”.
Create a box with scale 4,4,4, place it on the plane so it is just touching it, and make “Walls” it’s parent.
This box will be an obstacle in the scene, but why only one, why not add some more?
So duplicate the box and place it on the plane randomly, maybe with different scales and rotations for variation, but make sure all stays parented to the “Walls” gameObject.
Your scene should now look something like this:
The next thing you should do is to change the layer of the Walls gameObject to a layer named “Walls” (create one if it doesn’t exist), a dialog box will turn up asking if you would want to change the children too, press YES, this will make sure the walls can be separated from the rest of the scene.
Now add an empty gameObject and name it “A*”, and then add the AstarPath script to it.
Now you should see all the controls I described in part one.
The first thing you will notice is that the white boundary box isn’t placed correctly and it is way to large.
To correct this, change the offset of the grid to -50,-1,-50, and change the width and depth to 11 instead of 100, why 11 and not 10 you might wonder, well, the width and depth values indicate the number of nodes in one direction, but the first node is placed at position 0, so to fill out the last position we need another
Now if you have done everything correctly the white box should match up with the plane exactly, the reason the offsets y value is set to -1 is because I want to eliminate the floating point impression errors (i.e if I tell the script to search from position 0,0,0 it might search from 0,-0.000001,0 instead due to those errors which will make the point get outside the grids boundary).
Now, what happens if you press the Scan Map button?
Probably you will just get a bunch of red dots in the scene view, those represent unwalkable nodes, and the reason the nodes are unwalkable is because the script thinks the ground is an obstacle too, now the layering comes into place.
Open up the physics settings for the grid, make sure you use capsule mode, and change the layerMask to only include the “Walls” layer.
Now press the Scan Map button again, you should now see a grid instead of those red dots.
So now you have created a navMesh, but what about using it? Part 3