Visualizing Diagonal movement with GetContour

I’m having problems with Getcontour and diagonal movement. I’m making a turn-based game and I want all units to block their node and move diagonally.

I tried using BFS, which resulted in the below, which also is what I’m after, but afaik I can’t use traversals and constraints on BFS? Which means I can’t block units’ nodes?

BFS Code:

return PathUtilities.BFS(srcTile.node, maxDistance);

When I tried using ConstantPath with the same input (only *1000 for the distance input) it resulted in this:

Which won’t take diagonals into account…

ConstantPath code:

 ConstantPath path = ConstantPath.Construct(srcTile.GetPos(), maxDistance);
path.traversalProvider = GameControl.GetSelectedUnit().TraversalProvider;

NNConstraint constraint = NNConstraint.default;
constraint.distanceXZ = true;
if (!walkableOnly) constraint.constrainWalkability = false;

path.nnConstraint = constraint;

AstarPath.StartPath(path);
path.BlockUntilCalculated();

return path.allNodes;

TraversalProvider code:

blocker.manager = GridManager.blockManager;
traversalProvider = new BlockManager.TraversalProvider(GridManager.blockManager, BlockManager.BlockMode.AllExceptSelector, new List<SingleNodeBlocker> { blocker });

Any ideas/suggestions?

Hi

The ConstantPath does take diagonals into account, but it does so assuming that diagonals cost sqrt(2) ≈ 1.41 times more than a straight line cost, because those edges are sqrt(2) times longer.
You can enable costs that are uniform, i.e diagonals cost the same as straight lines, but only from a script at the moment.

AstarPath.active.gridGraph.uniformEdgeCosts = true;
AstarPath.active.Scan();
1 Like

And that solved it! I should have asked here a week ago :joy::stuck_out_tongue_closed_eyes:

One other thing though, it seems like my current traversalProvider don’t avoid other units’ nodes. I am sure I’m doing something wrong there, how would you do it?

Have you checked the example scene called ‘Turnbased’? it uses traversal providers in a similar way that you are using them I think.

1 Like