Struct NavMeshLineMod
Encourages A* on a navmesh to follow a straight line from start to goal.
Depending on the structure of your navmesh, this may be useful to get better looking straight paths. This is especially true for meshes that resemble a grid like structure. Because A* can only operate on the triangles itself, there may be many optimal paths to the destination that share the same cost (at the triangle level). If you use SSFA, then it may become apparent that the path that was chosen was not the most optimal after SSFA was performed. See this article for an in depth explanation: https://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#breaking-ties
This edge modifier mitigates this by dynamically adding a cost penalty to triangles that lie further away from a straight line between the start and the goal location. Causing A* to always prefer paths that are as close to a straight line as possible at the triangle level.
Note that when using this modifier, you must assign your pathfinding start and end locations manually before making the request! If you forget to do this, it will not work and produce unexpected paths. For this reason, this modifier is not suitable for pathfinding requests that have multiple stops in between.
finder.Stops.Add(from); // pathfinding start location
finder.Stops.Add(to); // pathfinding end location
finder.EdgeMod = new NavMeshStraightLineMod(from, to); // assign the straight line mod with our start+goal, obtained via a raycast
finder.Run(); // run the query
Implements
Namespace: AnyPath.Graphs.NavMesh
Assembly: AnyPath.dll
Syntax
public struct NavMeshLineMod : IEdgeMod<NavMeshGraphLocation>
Constructors
NavMeshLineMod(NavMeshGraphLocation, NavMeshGraphLocation)
Construct the mod using a navmesh start and end location
Declaration
public NavMeshLineMod(NavMeshGraphLocation start, NavMeshGraphLocation end)
Parameters
| Type | Name | Description |
|---|---|---|
| NavMeshGraphLocation | start | |
| NavMeshGraphLocation | end |
NavMeshLineMod(float3, float3)
Construct to mod using an arbitrary line in space.
Declaration
public NavMeshLineMod(float3 a, float3 b)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | a | |
| float3 | b |
Methods
ModifyCost(in NavMeshGraphLocation, in NavMeshGraphLocation, ref float)
Declaration
public bool ModifyCost(in NavMeshGraphLocation from, in NavMeshGraphLocation to, ref float cost)
Parameters
| Type | Name | Description |
|---|---|---|
| NavMeshGraphLocation | from | |
| NavMeshGraphLocation | to | |
| float | cost |
Returns
| Type | Description |
|---|---|
| bool |
ModifyEdgeBuffer(in NavMeshGraphLocation, ref NativeList<Edge<NavMeshGraphLocation>>)
Declaration
public void ModifyEdgeBuffer(in NavMeshGraphLocation from, ref NativeList<Edge<NavMeshGraphLocation>> edgeBuffer)
Parameters
| Type | Name | Description |
|---|---|---|
| NavMeshGraphLocation | from | |
| NativeList<Edge<NavMeshGraphLocation>> | edgeBuffer |