Funnel Modifier and Grid Graph

Hello there.

I started using A* Pathfinding for a RTS mobile game, and I’m testing all kind of stuff. I had a hard time getting the Navmesh Graph to work with the native 2D features of Unity, so I changed to the Grid Graph.

I’m using two Box Collider 2D as obstacles, marked with the Obstacles layer.

I’m giving orders to a group of tank to move across the obstacles. Without the funnel, it works fine. (I highlighted the path for better visibility)

But if I assign a funnel modifier to the tank amongst the seeker, here is what I have.

The path goes straight through the obstacle. I expected something like this :

For the detailed informations :

  • I’m using Unity 5
  • The Grid Graph use 2D Physics with Sphere collider and the Obstacle mask.
  • The Seeker script’s Start End modifier have a priority of 2
  • The Funnel script is on the same game object than the Seeker
  • The Funnel have a priority of 1

Is the funnel modifier the right stuff to use for the expected path? Or do I do something wrong?


Here is what I expected to happen :


That’s odd. It shouldn’t behave like that.
Are you updating your graph very often by any chance? What version are you using?

Hummm nope, I scan the graph only once in the editor then hit play. The path is created only once per mouse click. I am using version 3.7.4

Oh wait. You were using 2D.
Ah. That explains it. The funnel modifier is currently written for the XZ plane only, not the XY plane. I am doing a rewrite where this will be solved, but currently the funnel modifier does not work properly in the XY plane.

Just wtf.

I deleted the obstacles, scanned again, then placed a new one, with that same Obstacle layer, scan graph, it scan fine.

Then I apply again the funnel modifier and this time, it works. :x

You say it use the XZ planes, but I rotated the graph 90° on the X axis.

Now I don’t understand why it would do that. Just strange. I’m trying to reproduce the bug.

Haha, I added a second collider and here we are :

It turn over the first one correctly, but pass through the second one.

The funnel modifier needs to project the path down onto a single plane to be able to find the shortest path inside it. Currently it projects it down to the XZ plane. If it works in the XY plane will most likely boil down to floating point imprecision. You can try using the raycast simplifier instead.

I already tried the raycast simplifier but I had the same issue. Well I’ll just wait for a couple updates before using modifiers. :smile:



Make sure you use graph raycasting with the raycast modifier since just raycasting will use 3D physics, not 2D physics (really should fix that as well).

Well, you would be lovely to add a full support of Unity 2D capabilities for your framework, including some 2D Navmesh. :]

Seconded! I attempted to try to update the funnel modifier to work in 2d… and well, it was a mess. I’m just not knowledgable enough to understand what needs changing beyond the .z and .y flips.


I have actually been working on a funnel modifier that can work in 2D.
Here is a script called FunnelTest.cs

If you copy that to your project, you can call this funnel algorithm using

var path = ....;
var pathPart = new Funnel.PathPart {
     startIndex = 0,
     endIndex = path.path.Count,
     startPoint = path.vectorPath[0],
     endPoint = path.vectorPath[path.vectorPath.Count-1]
path.vectorPath = Funnel.RunFunnel(path.path, pathPart);

To get this to work in 2D space, simply open up the RunFunnel method and change these lines

leftArr[i] = ToXZ(funnel.left[i]);
rightArr[i] = ToXZ(funnel.right[i]);


leftArr[i] = (Vector2)funnel.left[i];
rightArr[i] = (Vector2)funnel.right[i];

Note that there are two RunFunnel methods, make sure you change the correct one.

I have not tried this myself, but I think it should work.