Class Funnel

Public

Implements the funnel algorithm as well as various related methods.

See

http://digestingduck.blogspot.se/2010/03/simple-stupid-funnel-algorithm.html

Usually you do not use this class directly. Instead use the FunnelModifier component.

using UnityEngine;
using Pathfinding;
using Pathfinding.Drawing;

public class FunnelExample : MonoBehaviour {
public Transform target = null;

void Update () {
var path = ABPath.Construct(transform.position, target.position);

AstarPath.StartPath(path);
path.BlockUntilCalculated();

// Apply some default adjustments to the path
// not necessary if you are using the Seeker component
new StartEndModifier().Apply(path);

// Split the path into segments and links
var parts = Funnel.SplitIntoParts(path);
// Optionally simplify the path to make it straighter
var nodes = path.path;
Funnel.Simplify(parts, ref nodes);

using (Draw.WithLineWidth(2)) {
// Go through all the parts and draw them in the scene view
for (int i = 0; i < parts.Count; i++) {
var part = parts[i];
if (part.type == Funnel.PartType.OffMeshLink) {
// Draw off-mesh links as a single line
Draw.Line(part.startPoint, part.endPoint, Color.cyan);
} else {
// Calculate the shortest path through the funnel
var portals = Funnel.ConstructFunnelPortals(nodes, part);
var pathThroghPortals = Funnel.Calculate(portals, splitAtEveryPortal: false);
Draw.Polyline(pathThroghPortals, Color.black);
}
}
}
}
}
In the image you can see the output from the code example above. The cyan lines represent off-mesh links.

Inner Types

Funnel in which the path to the target will be.

Part of a path.

Public Static Methods

Calculate (funnel, splitAtEveryPortal)

Calculate the shortest path through the funnel.

Public Static
ConstructFunnelPortals (nodes, part)
Public Static
Simplify (parts, nodes)
Public Static
Simplify (part, graph, nodes, result, tagPenalties, traversableTags)

Simplifies a funnel path using linecasting.

Public Static
SplitIntoParts (path)

Splits the path into a sequence of parts which are either off-mesh links or sequences of adjacent triangles.

Public Static

Public Static Variables

FunnelPortalIndexMask
Public Static
RightSideBit
Public Static

Public Enums

PartType

The type of a PathPart.

Public

Private/Protected Members

Calculate (unwrappedPortals, leftPortals, rightPortals, startPoint, endPoint, funnelPath, maxCorners, lastCorner)

Calculate the shortest path through the funnel.

Private Static
LeftOrColinear (a, b)

True if b is to the left of or on the line from (0,0) to a.

Private Static
RightOrColinear (a, b)

True if b is to the right of or on the line from (0,0) to a.

Private Static
Unwrap (leftPortal, rightPortal, leftUnwrappedPortal, rightUnwrappedPortal, point, sideMultiplier)
Private Static