• Articles
  • Api Documentation
Show / Hide Table of Contents
  • AnyPath
    • Graphs
      • Extra
        • Line2D
        • Line3D
        • Triangle
      • HexGrid
        • HexGrid
        • HexGrid.Enumerator
        • HexGridCell
        • HexGridHeuristicProvider
        • HexGridType
      • Line
        • ClosestLineLocationPredicate
        • LineGraph
        • LineGraph.Edge
        • LineGraph.Enumerator
        • LineGraphBuilder
        • LineGraphBuilder.ProtoEdge
        • LineGraphDrawer
        • LineGraphHeuristic
        • LineGraphLocation
        • LineGraphPopulator
        • LineGraphProcessor
        • LineGraphWelder
        • SceneGraph
          • LineGraphNode
          • LineSceneGraph
          • LineSceneGraphEdge
          • SceneGraphNodeEditor
      • NavMesh
        • ClosestNavMeshLocationPredicate
        • CornerAndNormal
        • IUnrolledNavMeshGraphPortal
        • NavMeshGraph
        • NavMeshGraph.EnterCostAndFlags
        • NavMeshGraph.Enumerator
        • NavMeshGraphCorners
        • NavMeshGraphCorners3D
        • NavMeshGraphHeuristic
        • NavMeshGraphLocation
        • NavMeshGraphUnroller
        • NavMeshLineBitmaskMod
        • NavMeshLineMod
        • NavMeshPlaneBitmaskMod
        • NavMeshPlaneMod
        • NavMeshPopulator
        • NavMeshWelder
        • SSFA
        • UnrolledNavMeshGraphPortal
      • Node
        • NodeGraph
        • NodeGraphNode
      • PlatformerGraph
        • ClosestPlatformerGraphLocationPredicate
        • PlatformerGraph
        • PlatformerGraph.Enumerator
        • PlatformerGraphBuilder
        • PlatformerGraphBuilder.ProtoEdge
        • PlatformerGraphDrawer
        • PlatformerGraphHeuristic
        • PlatformerGraphLocation
        • PlatformerGraphPopulator
        • PlatformerGraphProcessor
        • PlatformerGraphWelder
        • SceneGraph
          • PlatformerSceneGraph
          • PlatformerSceneGraphEdge
          • PlatformerSceneGraphNode
          • SceneGraphNodeEditor
      • SquareGrid
        • SquareGrid
        • SquareGrid.Enumerator
        • SquareGridCell
        • SquareGridHeuristicProvider
        • SquareGridHeuristicProviderEightDirectional
        • SquareGridHeuristicProviderManhattanDistance
        • SquareGridType
      • VoxelGrid
        • VoxelGrid
        • VoxelGrid.DirCost
        • VoxelGrid.Enumerator
        • VoxelGridCell
        • VoxelGridDirectionFlags
        • VoxelGridDirectionMod
        • VoxelGridHeuristicProvider
        • VoxelGridHeuristicProviderManhattanDistance
    • Managed
      • ClearFinderFlags
      • FinderExtensions
      • IFinder
      • IOptionReserver<TOption>
      • IOptionValidator<TOption>
      • ImmutableFinderException
      • ManagedDisposeExtensions
      • Results
        • DijkstraResult<TNode>
        • Eval
        • Eval<TOption>
        • MultiEvalResult
        • MultiPathResult<TSeg>
        • Path<TSeg>
        • Path<TOption, TSeg>
    • Native
      • AStarCheapestOption
      • AStarEvalOptionResult
      • AStarEvalResult
      • AStarFindOptionResult
      • AStarFindPathResult
      • AStarOption
      • AStarStops
      • AStar<TNode>
      • ComposedGraph<TGraph, TNode>
      • Edge<TNode>
      • FlagBitmask<TNode>
      • IEdgeMod<TNode>
      • IGraph<TNode>
      • IHeuristicProvider<TNode>
      • INodeFlags
      • IPathProcessor<TNode, TSeg>
      • NativeListWrapper<TSeg>
      • NoEdgeMod<TNode>
      • NoProcessing<TNode>
      • OffsetInfo
      • ReversedGraph<TNode>
      • EdgeMods
        • AdditionalAndExcludeEdges<TNode>
        • AdditionalEdges<TNode>
        • ExcludeEdges<TNode>
        • ExcludeLocations<TNode>
      • Heuristics
        • ALTCompute<TGraph, TNode>
        • ALTSerialization
        • ALT<TNode>
        • LandmarkSelection<TGraph, TNode, TEnumerator>
      • Util
        • IRefComparer<T>
        • NativeMinHeap<T, TComp>
        • NativeRefMinHeap<T, TComp>

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
You should test if this modifier is actually necessary for your use case, as in many cases and navmesh types, this offers no significant benefit and decreases performance slightly.
Implements
IEdgeMod<NavMeshGraphLocation>
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

Implements

IEdgeMod<TNode>

Extension Methods

FinderExtensions.AddOption<T, TNode, TOption>(T, TOption, TNode, TNode)
FinderExtensions.AddOptions<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRange<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRequest<T, TNode>(T, TNode, TNode)
FinderExtensions.AddRequests<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.AddStop<T, TNode>(T, TNode)
FinderExtensions.AddStops<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.SetComparer<T, TOption>(T, IComparer<TOption>)
FinderExtensions.SetEdgeMod<T, TMod>(T, TMod)
FinderExtensions.SetGraph<T, TGraph>(T, TGraph)
FinderExtensions.SetHeuristicProvider<T, TH>(T, TH)
FinderExtensions.SetPathProcessor<T, TProc>(T, TProc)
FinderExtensions.SetReserver<T, TOption>(T, IOptionReserver<TOption>)
FinderExtensions.SetStartAndGoal<T, TNode>(T, TNode, TNode)
FinderExtensions.SetValidator<T, TOption>(T, IOptionValidator<TOption>)
In This Article
Back to top Generated by DocFX