A* Pathfinding Project

Penalty for going against the flow?


#1

Hello, we are using your Astar pathfinder in our game, 911 Operator.
We work with large road graphs, that contain highways, local roads and one way roads too.

We would like to add some penalty for our emergency units for going against the one way roads flow (but they need that possible). Is it possible using Astar Pathfinder?
As far as i am concerned, we can only add tags to the nodes - and that wont help, as we use those nodes for intersections.
A tag penalty for a connection would solve our problem, but i dont know how to make that.


#2

Hi

Currently the scripts assume that if there is an edge going in both directions, then it will have the same cost. And in particular for grid graphs the edge costs are not even stored per node (since they would all be the same anyway).
If you are using a point graph you can get this to work however.
First you need to comment some code out.

In the PointNode.cs script there are some lines that look like this

else if (pathOther.G+tmpCost+path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this)) {
	//Or if the path from the other node to this one is better

	pathNode.parent = pathOther;
	pathNode.cost = tmpCost;

	UpdateRecursiveG(path, pathNode, handler);
}

You will need to comment those out.

Then you can use the NodeLink component (or the node.AddConnection API) to set different costs for different connections (all components should have ‘oneWay’ set to true).

I think this should work anyway, I haven’t tested it myself.


#3

Thanks, it looks like it helps!
I just skipped the tags and only made a cost bigger for going against the flow.

Is this the only place i needed to make changes?


#4

Assuming you are using only a point graph, yes.