Finding the fastest way with breakable obstacles

Hello,
I have a game where are buildings and walls. All builndigs and walls cannot be passed, but can be destroyed. To destroy each one of them takes some time depending on attack damage and attack delay of unit. My question is how to find out which path: around a wall or by destroying a wall is faster? I have no idea how to check it. Could anyone give a hint?

Thank you,
Adam.

The solution is to use penalties for obstacles. A high penalty means that a unit will try to avoid it, but will still path through it if it is the best choice.
See http://arongranberg.com/astar/docs/graph-updates.php

Thank you very much, I’ll check it out.

It’s been some time, but I tried using penalties this way:
When wall is added to scene I add in Start() new component GraphUpdateScene I set points and really high penalties, then I use AstarPath.active.UpdateGraphs(boxCollider.bounds).

When wall is destroyed I set penalty to 0, then set active to false for gameObject and after that I updateGraphs same way as above. After that Seekers are asked to find new path.

Somehow it is not working, and seeker is finding path that pass over two obstacles, even when close to him are nodes without penalty.

What could be wrong?

Thank you,
Adam.

I figured out what is going on. When walls are created GraphUpdateScene points are same as boxCollider vertices important is that each wall is next to each other so there are no nodes without penalty. At this point units pass walls like there is nothing on their path, even after some parts of the wall are removed and units are asked to find new path (after graph update) they dont care and even pass two or three other walls (when they should find path around). Penalties don’t help even 2147483647 value :slight_smile: I also tried to change node size but it didn’t help.

Solution to this problem is to check if walls are next to each other and then creating one big GraphUpdateScene for all of them. This way units avoid walls. I wonder why it works for bigger areas rather than smaller.

Is there any other solution for this?

Thanks,
Adam.

Hi

Maybe the graph update object’s bounds you create will not contain any nodes in the graph. It might be too small. Try to debug it using the Debug Mode set to Penalty in A* Inspector -> Settings.

After debugging now I know that when graph update object’s bounds are too close to each other (or too close to an edge of the graph), nodes on the graph are without penalty.

I add screen shot as an example.
Image url

I really need them to have seperate guos (not one big guo). Any ideas how this might be fixed?

Thanks,
Adam.

Hm. Not really sure what causes the problem. But try upgrading to version 3.2(.1). It has some fixes for grid graph updates, perhaps it is a bug which was fixed by that.

Yup it helped, now everything is working good, even when gus overlap each other. If it matters my version was 3.1.1 now I use 3.2.1.

Thank you for time,
Adam.