Working on TowerDefense game, I’m using MultiTargetPath instead of FloodPath because in game maze dynamically created by players. Game has 4 Lane players can build their own maze at those lanes, here is the Node graph ;
Well problem is, if user completely block the lane (Target is unreachable), MultiTargetPath is ignoring Tower colliders finding a new path over Towers. I couldn’t find any function that I can check on MTP before assigning that newly calculated path to creeps. MTP setup like ;
When I try to use ABPath, if player block the lane creeps were still keep moving to blocking point of lane at that position I was able to destroy blocking Towers in area with creep after couple of seconds.
Using MTP In game behavior ;
Unfortunately this is due to the way the multi target path works. If you request a path using a multi target path from multiple sources to a single target, it will internally calculate the path from the single target to multiple sources and then reverse all the paths at the end. That’s because it is only then it can share the calculations for all different paths.
What is happening now is that the multi target path will find a valid path from the target to the closest point it can reach to the units, which happens to be on the other side of the towers.
What you could do instead of completely blocking the path, you could set a high penalty (say a 1000000 which should be enough for a map your size, assuming that one tower is one world unit wide). Then the units will avoid the towers if possible, but try to walk through them if necessary (which you could detect and make them stop and attack the towers instead). Further, if the player builds two rows of towers which blocks the units, they will try to find the weak spot (say that in one case they could go make it to the target by only destroying a single tower instead of two).
Also. Note that if you disable the heuristic, you will likely drastically increase the time it takes for a path to be calculated (but your graph is pretty small, so it might not matter much).
Thanks for your reply, I’ll try as you suggest giving penalties to turrets and I will post the result, btw, my gird is 100x100 each grid is 1x1 turrets are 2x2 and the reason is why I disabled the heuristic if a player spawns a batch of creeps and then changes the graph all affected creeps follows the same path (In some scenario long path) with Sequential mode, yeah path computation is kinda takes much time without heuristic as you mentioned but it’s fine in my case. Finally if creeps are blocked they are exploding and destroys towers in their explosion range , fancy explosion effect is missing right now
Enlarging bounds could be a problem, My creeps is able to move in one cell and Player could make a maze freely, if I enlarge bounds it will also block vertical between 2 rows, but I’m gonna give a try, then I’ll be back xD.
Hm. I think you should try moving the nodes (0.5, 0.5) units so that a tower can occupy 4 cells (note that the center of a node is where the lines meet, what you see in the scene view are the connections between the nodes), otherwise there will be no way to apply the penalties in a good way.
Actually my grid was like exactly what you said. All of my tries failed with that grid setup and then I tried to giving offset to grid Going back to old setup as you mentioned but it didn’t work before I’ll give it a try again.
I moved the grid as before, here is the 2 types of turrets red turrets are using colliders and crosbow turrets are using penalties and the Penalty bounds are 2.1 x 2.1 ;
Oh, I sense Ninja editing on this post or I miss that part Well disabling updatePhysics is the trick ! It looks much better right now only problem is placing turrets diagonally doesn’t work. See images,
Also can you link me the doc about, how can I find if my creep moved into penalized area.
Thanks for your time and I’m sorry for so much trouble.
PS! even stripping Pathfinding part on our project will take same time, probably I’m gonna create an example project about that.
[Edit]
I tried increasing bounds on GUO 2.0 to 2.75f it didn’t change anything. If I make to 3f it also blocks that horizontal 1 cell movable area between rows. And creep moves over first tower.
Ah. Didn’t think about diagonal moves.
Hm… Unfortunately I don’t think that is possible to solve without hacking a bit in the core scripts.
I think this will solve it:
In the GridNode.cs script, find the Open method.
After these lines (around line 920)
GridNode other = nodes[nodeInGridIndex + neighbourOffsets[i]];
if (!path.CanTraverse (other)) continue;
PathNode otherPN = handler.GetPathNode (other);
uint tmpCost = neighbourCosts[i];
Add
if (i >= 4) {
// Diagonal move
// Pick the two nodes that this diagonal move will touch
var otherA = nodes[nodeInGridIndex + neighbourOffsets[i-4]];
var otherB = nodes[nodeInGridIndex + neighbourOffsets[(i-4+1) % 4]];
// The denominator might need to be adjusted, but I think 4 should work
tmpCost += (otherA.Penalty + otherB.Penalty)/4;
}
You can detect if the closest node has a penalty by using
var node = AstarPath.active.GetNearest(myPosition).node;
if (node.Penalty > 0) {
// !!
}