I have a 2d procedurally generated landscape with AI agents travelling across it it towards a goal. Different parts of the landscape have different effects on the AIs speed. I’m using movement penalties per node to simulate AI route planning and that’s working well. They follow sensible paths through the landscape to get them quickly to the goal. I’m using GridGraph.
At the beginning of a ‘round’, the AIs are constrained within a rectangular start zone (pushing against a border) at the left edge of the map until a countdown has ended. They can move quickly inside this zone. I would like them to adopt optimal positions in this start zone with respect to the rest of the path they will follow. But what currently happens is that their start position isn’t optimal. Their Seeker paths extend diagonally out of the start zone to get to the first ‘fast’ zone that their path takes them through, while the paths ought to first reach a position in the start zone that’s vertically aligned with the first ‘fast zone’ they want to get to once the countdown ends.
I think this problem has do do with the inherent cost of moving between nodes (connection cost?) within the start zone. And what I think i need to do is find a way to specify that connection costs to/from certain nodes (i.e. all nodes corresponding to positions inside a start zone) are 0. (I already have code working that detects what terrain type a node corresponds with).
- Does this sound like a sensible solution?
- How would I go about specifying zero connection costs for a node in a GridGraph?
Thanks!
Hi
So the problem that you want to solve is, if I understand your description correctly.
What is the closest node inside the start zone to the target that I want to reach?
Does that sound about right?
Currently your agents are optimizing for the shortest total path cost, including the movement cost inside the start zone, which is obviously not what you want.
From this it sounds like you want the same behavior as the user in this post: Find nearest reachable Node with specific tag - #4 by aron_granberg assuming you tag the nodes in your start region.
So you would start a path from where your units’ final position and search for the closest node in the starting region, then you can tell your units to move to that node.
You cannot set the connection cost to exactly zero because that will unfortunately break the algorithms a lot since the path with the lowest cost could for example go around in a circle 100 times and then move to the target and still have the same cost as one that moved to the target immediately. A very low cost is possible, but I would recommend that you try the solution above first.
Ah I see! that’s neat. I will try it out.
The compiler is grumbling about not being able to find class PathEndingCondition when i try to implement that solution. Is this something in the pro version only?
Ah, yes. It only exists in the pro version.
You could increase the penalty of the non-starting region to some very high value to emulate this behavior a bit, however this will have the side effect of slower path calculations and if you set the penalties too high, things might start to overflow (relatively unlikely however).