A* Pathfinding Project
3.1.4
The A* Pathfinding Project for Unity 3D
|
Automatically generates navmesh graphs based on world geometry. More...
Classes | |
struct | ExtraMesh |
struct | Int2 |
struct | SceneMesh |
Public Member Functions | |
void | AddPortal (Node n1, Node n2, List< Vector3 > left, List< Vector3 > right) |
void | BuildFunnelCorridor (List< Node > path, int startIndex, int endIndex, List< Vector3 > left, List< Vector3 > right) |
bool | CollectMeshes (out MeshFilter[] filters, out ExtraMesh[] extraMeshes) |
override Node[] | CreateNodes (int number) |
Creates a number of nodes with the correct type for the graph. | |
override void | DeserializeExtraInfo (byte[] bytes) |
Deserializes graph type specific node data. | |
void | DeSerializeNodes (Node[] nodes, AstarSerializer serializer) |
void | DeSerializeSettings (AstarSerializer serializer) |
override NNInfo | GetNearest (Vector3 position, NNConstraint constraint, Node hint) |
Returns the nearest node to a position using the specified NNConstraint. | |
override NNInfo | GetNearestForce (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified constraint. | |
List< MeshFilter > | GetSceneMeshes () |
bool | Linecast (Vector3 origin, Vector3 end) |
bool | Linecast (Vector3 origin, Vector3 end, Node hint, out GraphHitInfo hit) |
bool | Linecast (Vector3 origin, Vector3 end, Node hint) |
override void | OnDrawGizmos (bool drawNodes) |
override void | Scan () |
Scans the graph, called from AstarPath.Scan Override this function to implement custom scanning logic | |
void | ScanCRecast () |
override byte[] | SerializeExtraInfo () |
Serializes graph type specific node data. | |
void | SerializeNodes (Node[] nodes, AstarSerializer serializer) |
void | SerializeSettings (AstarSerializer serializer) |
void | SnapForceBoundsToScene () |
void | Sort (Int3[] a) |
void | UpdateArea (GraphUpdateObject guo) |
Public Member Functions inherited from NavGraph | |
virtual void | Awake () |
This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to. | |
NNInfo | GetNearest (Vector3 position) |
Returns the nearest node to a position using the default NNConstraint. | |
NNInfo | GetNearest (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified NNConstraint. | |
bool | InSearchTree (Node node, Path path) |
Returns if the node is in the search tree of the path. | |
virtual Color | NodeColor (Node node, NodeRunData data) |
virtual void | OnDestroy () |
Function for cleaning up references. | |
virtual void | PostDeserialization () |
Called after all deserialization has been done for all graphs. | |
virtual void | RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix) |
Relocates the nodes in this graph. | |
void | SafeOnDestroy () |
SafeOnDestroy should be used when there is a risk that the pathfinding is searching through this graph when called | |
void | ScanGraph () |
Consider using AstarPath.Scan () instead since this function might screw things up if there is more than one graph. | |
Public Member Functions inherited from ISerializableGraph | |
Node[] | CreateNodes (int num) |
void | DeSerializeNodes (Node[] nodes, AstarSerializer serializer) |
void | SerializeNodes (Node[] nodes, AstarSerializer serializer) |
Public Member Functions inherited from ISerializableObject | |
void | DeSerializeSettings (AstarSerializer serializer) |
Called to deserialize the object. | |
void | SerializeSettings (AstarSerializer serializer) |
Called to serialize the object. | |
Public Member Functions inherited from IRaycastableGraph | |
bool | Linecast (Vector3 start, Vector3 end) |
bool | Linecast (Vector3 start, Vector3 end, Node hint) |
bool | Linecast (Vector3 start, Vector3 end, Node hint, out GraphHitInfo hit) |
Public Member Functions inherited from IFunnelGraph | |
void | AddPortal (Node n1, Node n2, List< Vector3 > left, List< Vector3 > right) |
Add the portal between node n1 and n2 to the funnel corridor. | |
void | BuildFunnelCorridor (List< Node > path, int sIndex, int eIndex, List< Vector3 > left, List< Vector3 > right) |
Public Member Functions inherited from IUpdatableGraph | |
void | UpdateArea (GraphUpdateObject o) |
Updates an area using the specified GraphUpdateObject. | |
Static Public Member Functions | |
static string | GetRecastPath () |
Public Attributes | |
bool | accurateNearestNode = true |
More accurate nearest node queries. | |
float | cellHeight = 0.4F |
Voxel sample size (y) | |
float | cellSize = 0.5F |
Voxel sample size (x,z) | |
float | characterRadius = 0.5F |
float | contourMaxError = 2F |
Max distance from simplified edge to real edge. | |
Vector3 | forcedBoundsCenter |
Center of the bounding box. | |
Vector3 | forcedBoundsSize = new Vector3 (100,40,100) |
Size of the bounding box. | |
bool | includeOutOfBounds = false |
bool | includeTerrain = true |
Include the Terrain in the scene. | |
LayerMask | mask = -1 |
Masks which objects to include. | |
float | maxEdgeLength = 20 |
Longer edges will be subdivided. | |
float | maxSlope = 30 |
Max slope in degrees the character can traverse. | |
int | regionMinSize = 8 |
bool | showMeshOutline = false |
Show an outline of the polygons in the Unity Editor. | |
int | terrainSampleSize = 3 |
Controls how large the sample size for the terrain is. | |
bool | useCRecast = false |
Use a C++ version of Recast. | |
float | walkableClimb = 0.5F |
Height the character can climb. | |
float | walkableHeight = 2F |
Character height. | |
Public Attributes inherited from NavGraph | |
byte[] | _sguid |
Used to store the guid value. | |
AstarPath | active |
Reference to the AstarPath object in the scene. | |
bool | drawGizmos = true |
bool | infoScreenOpen |
Used in the editor to check if the info screen is open. | |
uint | initialPenalty = 0 |
Matrix4x4 | matrix |
A matrix for translating/rotating/scaling the graph. | |
string | name |
Node[] | nodes |
All nodes this graph contains. | |
bool | open |
Is the graph open in the editor | |
Properties | |
BBTree | bbTree [get, set] |
Bounds | forcedBounds [get] |
Vector3[] | vectorVertices [get] |
Int3[] | vertices [get, set] |
Properties inherited from NavGraph | |
Guid | guid [get, set] |
Used as an ID of the graph, considered to be unique. | |
Matrix4x4 | inverseMatrix [get] |
Properties inherited from INavmesh | |
BBTree | bbTree [get, set] |
Bounding Box Tree. | |
Int3[] | vertices [get, set] |
Private Attributes | |
BBTree | _bbTree |
Bounding Box Tree. | |
Vector3[] | _vectorVertices |
Int3[] | _vertices |
Automatically generates navmesh graphs based on world geometry.
The recast graph is based on Recast (http://code.google.com/p/recastnavigation/).
I have translated a good portion of it to C# to run it natively in Unity. The Recast process is described as follows:
It works exactly like that in the C# version as well, except that everything is triangulated to triangles instead of n-gons. The recast generation process completely ignores colliders since it only works on an existing "polygon soup". This is usually a good thing though, because world geometry is usually more detailed than the colliders.
In the editor there is a button for exporting the generated graph to a .obj file. Usually the generation process is good enough for the game directly, but in some cases you might want to edit some minor details. So you can export the graph to a .obj file, open it in your favourite 3D application, edit it, and export it to a mesh which Unity can import. Then you assign that new mesh to the "Replacement Mesh" field right below the export button. That mesh will then be used to calculate the graph.
Since many 3D modelling programs use different axis systems (unity uses X=right, Y=up, Z=forward), it can be a bit tricky to get the rotation and scaling right. For blender for example, what you have to do is to first import the mesh using the .obj importer. Don't change anything related to axes in the settings. Then select the mesh, open the transform tab (usually the thin toolbar to the right of the 3D view) and set Scale -> Z to -1. If you transform it using the S (scale) hotkey, it seems to set both Z and Y to -1 of some reason. Then make the edits you need and export it as an .obj file to somewhere in the Unity project. But this time, edit the setting named "Forward" to "Z forward" (not -Z as it is per default).
|
virtual |
Creates a number of nodes with the correct type for the graph.
This should not set the nodes array, only return the nodes. Called by graph generators and when deserializing a graph with nodes. Override this function if you do not use the default Pathfinding::Node class.
Reimplemented from NavGraph.
|
virtual |
|
virtual |
Returns the nearest node to a position using the specified NNConstraint.
position | The position to try to find a close node to |
hint | Can be passed to enable some graph generators to find the nearest node faster. |
constraint | Can for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce. |
Reimplemented from NavGraph.
|
virtual |
Returns the nearest node to a position using the specified constraint.
position | A Vector3 |
constraint | A NNConstraint |
Reimplemented from NavGraph.
|
virtual |
Scans the graph, called from AstarPath.Scan Override this function to implement custom scanning logic
Implements NavGraph.
|
virtual |
Serializes graph type specific node data.
This function can be overriden to serialize extra node information (or graph information for that matter) which cannot be serialized using the standard serialization. Serialize the data in any way you want and return a byte array. When loading, the exact same byte array will be passed to the DeserializeExtraInfo function.
These functions will only be called if node serialization is enabled.
If null is returned from this function, the DeserializeExtraInfo function will not be called on load.
Reimplemented from NavGraph.
|
private |
Bounding Box Tree.
Enables really fast lookups of nodes.
bool accurateNearestNode = true |
More accurate nearest node queries.
When on, looks for the closest point on every triangle instead of if point is inside the node triangle in XZ space. This is slower, but a lot better if your mesh contains overlaps (e.g bridges over other areas of the mesh). Note that for maximum effect the Full Get Nearest Node Search setting should be toggled in A* Inspector Settings.
Vector3 forcedBoundsCenter |
Center of the bounding box.
Scanning will only be done inside the bounding box
Vector3 forcedBoundsSize = new Vector3 (100,40,100) |
Size of the bounding box.
bool includeTerrain = true |
Include the Terrain in the scene.
float maxEdgeLength = 20 |
Longer edges will be subdivided.
Reducing this value can improve path quality since similarly sized polygons yield better paths than really large and really small next to each other
int terrainSampleSize = 3 |
Controls how large the sample size for the terrain is.
A higher value is faster but less accurate
bool useCRecast = false |
Use a C++ version of Recast.
The C++ version is faster and has more features, though right now the features are quite similar because I haven't added support for them yet.
The C++ version can only be used in the editor or in standalones and it requires a special file to be placed inside the executable for standalones.
When deploying for mac, the Recast file (which can be found in the AstarPathfindingProject folder) should be copied to a new folder myApplication.app/Contents/Recast/