- Home /
How can I get my pathfinding algorithm to know that it cant go through certain sides of tiles
Im creating a turn based strategy game where the player can build the board over time by placing square tiles. They can rotate them before placing them. Then they will control a character that will navigate this board.
Some tiles are only open on 2 or 3 sides. How could I create a pathfinding system that for example is able to detect that it can only move through the top and bottom of a tile because the tile has walls on the left and right, even though there are tiles adjacent to it on the left and right.
I am planning on using Astar but my issue is that even though 2 tiles are next to each other, I need the algorithm to know it cant direct go onto that tile because the tile its on is not open on that side.
Answer by Casiell · Mar 11, 2020 at 07:34 AM
I recommend first implementing the algorithm as is and then worrying about walls. I'm saying that because when you actually implement the algorithm you realize it should be insanely easy. You could either not create a connection between "walled" tiles at all, or if for some reason you really need it, you can set the weight of that connection to infinity, so the algorithm will always choose another way
Ahh okay. Thank you for the fast response. I know how Im going to place the tile gameObjects in the scene but im not sure how im going to pathfindg through them. Would you happen to have a best method for storing the grid that can be used for pathfinding. I've never had to do anything like this before so Im not sure if i can pathfindg through the GameObjects or if I should be storing a copy of the tile grid in a text file that can be queried or something like that. Any methods or guides you could recommend would be greatly appreciated thanks.