How to adjust path 'length' when cutting a corner using 8 connections

Hi Aron,

So I’m updating my engine for “Dungeon Crawlers” and working on the next title, I’d love to bump up from 4-sided connections to 8-sided, So that characters don’t do the old left/right jagged walk. but i still want the cost of cutting a corner to cost 2 tiles (or nodes) (as if it were 4-sided). A good example of this is the pathfinding in “Invisible Inc.”.

Is there a way to modify the pathfinding to give me the numbers i want?

Hi

Sure. However I suggest modifying it so that it costs 1.95 times a straight edge to encourage diagonals.

Open GridGenerator.cs and find the method SetUpOffsetsAndCosts. In that method you can find the diagonalCost variable. Modify it so that it costs 1.95 instead of the square root of 2 times the straight cost.

Just out of curiosity. Why do you want this? I cannot think of any scenarios where it would be particularly important.

While we’re on the topic, I noticed I get “path length” from executing the command:

p.DebugString (logPathResults);

but what other method allows me to access the paths length?

Depends if you want the length as in the number of nodes traversed or the actual world space length.

int numberOfNodesInPath = path.nodes.Count;
float worldSpaceLength = path.GetTotalLength ();

perfect. Thanks for all the info! Back to work :wink:

Oh, I didn’t see your earlier Q. Well like i said, I want to allow users a quicker way to cut from tile to tile, but still charge them the full amount for doing so. Why walk over 1 square and up 1 square, when they can just cut diagonally? But I don’t want the diagonal to cost 1 tile, I want it to cost 2. If I use the 8-direction grid, it still costs 1.

Ok.
But just a clarification. When you use a 8-directional grid then diagonals costs sqrt(2) ≈ 1.41 times the straight cost.