Ok, awesome! I usually always test out my solutions in the version currently on the marketplace, but I forgot myself here initially. Glad it worked out.
No worries It was fun to take a break from cleaning up code and bug testing for while. One thing I forgot to add is that you also have to make sure you reduce the integers in the AI Sight array not only when an AI unit moves, but also when it dies. Good luck with implementation!
The reasoning behind this is fairly complex and I agree that it is a bit counter intuitive. Frankly I’ve been testing back and forth with various methods for a long time now, and there are benifts and drawbacks to both solutions. The version you are using (the one on the marketplace) mostly checks the tile you are entering. It does this for both movement cost and edges that are blocked. However, in addition the tile you are exiting is checked for having an edge cost of 0. This was a necessary shortcut when I added walls between edges, as otherwise all such walls would have been single-sided.
As I’ve continued to experiment with the toolkit I’ve slowly been trying to head towards a pathfinding solution that is less dependent on the predictable spatial relationship of a grid. The method of checking the edge of the tile you are entering only works if indexes have a predictable spatial relationship. As an example when going from tile 1 to 2 you know from the grid that 2 should be east of 1, which means we can check the western edge of 2. However, if tiles could for instance be placed freely by the player this predictable relationship would disappear. One solution in this case is to store the indexes a tile is connected to as well as the edge costs to get to those indexes within each array index, which in practice means that you check the edge of the tile you are leaving. This is beneficial as I move on to adding things like true multi-level grids where tiles might have connections to more than 8 neighbors or even to different sub-grids.
This way of making pathfinding grids is whats called a directinal graph in graph theory, which is probably the most flexible and powerful way to represent pathfinding if you want to be able to add things like edges having different costs in different directions (think sloped hills) or one-way doors. Here is what a directional graph looks like:
This is all well and good, but as you have become aware there are some serious drawbacks to this solution. It really makes a lot more sense when you add an impassable wall to simply make the edges of the index where you added the wall 0 instead of the edges facing this tile of all surrounding tiles. To combat this I’ve added some fairly complex functions that let users say that they want to add a tile to an index, but that in practice adds its edges to all surrounding tiles. Here is one of these functions:
These things work under the hood and are run at startup, meaning they will not have an impact on actual game performance. For users who don’t want to tinker with the fundamentals of the toolkit this works great, but for advanced users such as yourself who want to manipulate the grid (as well as myself) it can in some cases become pretty tiresome. I’m debating with myself what solution is the best and if I can find some working middle ground. This is actually one of the main reasons the update has been delayed. Altering the fundamentals of the toolkit takes work, and I’ve been back and forth with several solutions, and now it seems I might do so again. Adding a switch between two methods is not something I would like to do. These changes to the toolkit are so fundamental that there would have to be a lot of switches to clutter up the toolkit, and supporting both methods in all future updates for any additional features would be a nightmare.
I hope I’ve given you some insight into my reasoning. To repeat, though, for the version you have the toolkit checks the edge it is entering, although it also checks if the tile it is leaving has an edge cost of 0. Please let me know what solutions you would find the most intuitive. I welcome any feedback and suggestions