Recast graph pathfinding with funnel modifier produces unoptimal paths

Hello. I just bought the pro version and it seems very functional. However, when I use a recast graph and seekers with a funnel modifier to calculate a path, I don’t get direct paths to the target. Example in picture. I’ve highlighted the path generated by the seeker:
funnel1

When I give this path to RichAI, its own funnel algorithm does skip the detour, but I need to have the final path (or at least something resembling it) to visualise it for the player.

Adding raycast smoothing modifier gave me better results (at least on highest detail level), but I don’t think that’s the correct answer here. I tried launching the scene with all combinations on the funnel modifier booleans, but they didn’t seem to have an effect. What should I do?

This topic seems to be related to this but I’m not sure if it reached any proper conclusion or if it’s relevant:

E: Using Unity 2019.2.8f and A* v. 4.2.8

Using raycast modifier doesn’t seem that good even as a temporary solution as it sometimes makes the path go through a wall.

Is there a way to try earlier versions to see if the funnel modifier behaves differently on them? I don’t think Unity Asset store allows getting an older version, though maybe I’m missing something.

If you wanna download an older version you can do so from the website here: https://arongranberg.com/astar/download

I did some quick testing on my own.
I used the default settings for all the components:
Rich AI (Funnel Simplification turned off)

Default Funnel Modifier:

Default Funnel Modifier and Simple Smooth:

If you only want to use this for showing the player the planned path I’d opt both Funnel Modifier and
Simple Smooth Modifier. Though I’d disable them for navigation, as the RichAI will already perform the more direct path.

Thank you for the reply. I was also just playing around with the recast graph example scenes, and it does seem like this same issue can be demonstrated on those as well:

funnelvsmall

Now I don’t think smoothing will work out here.

I suppose my options are

  1. using the raycast modifier and fiddle around with the settings to see if I can get a satisfying result.
  2. Use grid graph for the preview path.
  3. Something else.

I also noticed that given a scenario like in my last screenshot, most of the time the RichAI agent (I replaced the AI Path) will go straight towards the path end. Great. However, occasionally it will start moving along the border of the two top left sections, ping ponging between taking a straight path to the finish and following the original path plan. I can take a video of this if it’s unclear, but I don’t have any screen capture software set up on my current computer so maybe a description will suffice.

I feel like I’m missing something here. I can’t be the only one struggling with traveling through open areas.

Hi

Adding the same simplification code that the RichAI uses to the Funnel Modifier is something I have had on my todo list for a long time. So today I did it. I have uploaded a new beta (4.3.7, you can find it here: https://www.arongranberg.com/astar/download) which includes a quality field on the Funnel Modifier. Setting it to high will make it use the same simplification as the RichAI script. It is not perfect, it can still take somewhat weird paths, but it is way less likely with the simplification enabled.

Thank you! I haven’t had time to test it out yet but I’ll report as soon as I do so. I assume I can take the Funnel modifier out of the new version and use it with the old one? I wouldn’t want to update my Unity version to 2019.3 beta because I fear that’s usually just asking for trouble. :grimacing:

Sorry for the late answer.
You will need the FunnelModifier.cs script and the Funnel.cs script. If you copy those to the old version I think they will still work.

It’s alright, I didn’t have time to test this before today, anyway. :slight_smile:

Thank you very much. The new funnel modifier on high setting seems to function as expected!

The medium quality setting seems bad to the point of uselessness, so unless there’s some use case I’m not aware of, it might be worth removing it or at least setting the default to high.

Anyway, thank you for support! Surely this library’s good reputation is well placed!

One thing, though: I’m not sure if this bug was present in the previous version as well or if the handling for this particular case is just done somewhere else in the new version, but trying to calculate a path for which the start and end are the exact same spot results in an error. Not a big deal and easy for me to avoid, but figured you might be interested.

If unwrap is on, it happens on this line:
var normal = Vector3.Cross(funnel.right[1] - funnel.left[0], funnel.left[1] - funnel.left[0]);

and if unwrap is off, this is where it fails:
Vector2 prev2D = leftArr[0];

both in funnel.cs and both index out of bounds errors.

Well actually it seems like even non zero length path calculation requests can result in this same error. Not sure what the exact conditions are.