Class Funnel


Implements the funnel algorithm as well as various related methods.


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);


// 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.isLink) {
// 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, unwrap: true, splitAtEveryPortal: false);
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, unwrap, splitAtEveryPortal)

Calculate the shortest path through the funnel.

Public Static
ConstructFunnelPortals (nodes, part)
Public Static
ShrinkPortals (portals, shrink)
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
Unwrap (funnel, left, right)

Unwraps the funnel portals from 3D space to 2D space.

Public Static

Private/Protected Members

Calculate (left, right, numPortals, startIndex, funnelPath, maxCorners, lastCorner)

Funnel algorithm.

Private Static
FixFunnel (left, right, numPortals)

Try to fix degenerate or invalid funnels.

Private Static
FromXZ (p)
Protected Static
LeftOrColinear (a, b)

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

Protected Static
RightOrColinear (a, b)

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

Protected Static
ToXZ (p)
Protected Static
UnwrapHelper (portalStart, portalEnd, prevPoint, nextPoint, mRot, mOffset)
Private Static