2D Path Gen on 3D terrain

Hello, I’m using a manual path generation for moving some large unit formation over a terrain. One thing I have noticed is that the paths I generate tend to prioritize going around hills etc…which might be desirable for some games, but I actually want them to do a more or less 2d path projected onto the 3d terrain. I do it like this currently

var p = ABPath.Construct(_unit.Position, endPos, OnPathComplete);

 int[] tagPenalties = new int[32];
///... add some penalties etc...

path.nnConstraint = NNConstraint.None;
path.tagPenalties = tagPenalties;
AstarPath.StartPath(p);

Looking into the the path generating code, the GetNearest() node stuff to a position calculates:

float dist = ((Vector3)nnInfo.clampedPosition-position).magnitude;

is that where this distance is done for each point along a vectorpath? Is there a setting, paramter, constraint or whatever to have it only take horizontal or xz distance into account and not y distance, ie so it would rather go a short distance over a hill than a longer distance around it?

Hi

Do you have a screenshot of this?
What graph type are you using?




Hi, thanks for the reply, see attached pictures of the graph settings and of the path debugged in yellow, it might be kind of hard to see, but the first picture shows one roughly striagt graph and another that takes a 90 degree ish turn around a hill, the latter being easier to see on its own in the second terrain pic

I’ll also say I’m not 100% sure I am diagnosing it correctly, but basically I don’t want these very broad 90 degree turns but instead for the unit to go basically straight do it’s destination (unless navigating around higher cost terrain but that’s not on this part of the map or part of this question, but i do use tag penalties elswhere). I also use a smooth path modifier with these settings:
modifier.maxSegmentLength = Universals.u.pathMaxSegmentLength;//value: 20
modifier.strength = Universals.u.PathModifierSmoothStrength;//value: 1.0

Hi

The grid graph does not change its cost depending on the slope or anything. However, there are many paths on a grid graph that are equally long. See Pathfinding - A* Pathfinding Project for more details.
You may want to disable the Heuristic Optimization that you are using. I’m not quite sure how it interacts with pathfinding in this case.

If you want to simplify the path more, you can do that as a post-processing step. For example using the FunnelModifier (in v5) or RaycastModifier (in 4.2.19 or lower).

ok thanks I’ll test those out, turning off the heuristic optimization seems to have mitigated the issue.

1 Like