I am making an RTS game with square tiles and am trying to figure out how to do pathfinding
I have looked on the devforum and youtube but can not find what I need
Does anyone know how to create the points for pathfinding system on the grid tiles? I just need to know the points
I am making an RTS game that has square tiles, I want to have a pathfinding system when an NPC is moved.
I drew a diagram, yellow is the path finding points, yellow is the npc, brown is the house, and orange is the path the npc will take. The last pathfinding point is where the npc will go
I’ve already watched that exact video and can not understand it, I have looked into A star and just do not understand some of it. I understand the general idea but drawing the line is what I do not understand
Pathfinding at its core is basically searching every tile and tracking a list of what tile you should have come from to get there most efficiently. Once you find the end, you can just walk to the parent tile (the one you should have come from) over and over storing them as you go, until the parent tile is registered as nil (which is only true for the start). From there you have a completed path (though technically backwards, so it’s easiest just to flip the start/end if you know a path exists). You seem to only care about turns though, so after you get the path, you’ll process it a bit more to only get the nodes where the direction changed in a new list and that new list is the path as you desire it.
The thing I do not understand is just drawing the line at the end, I understand checking all the nodes and everything but the final line I do not understand. Same for pretty much every other pathfinding tool
I have been scripting for the past 7 years, I have spent 3 weeks studying path finding, and I do not even have chat gpt and I do understand almost all of A* besides drawing the final line
Alright. Let’s assume you have a path. The path being a position of every cell along it. The line you want is just where it would turn. So to do this we go through your path and start by adding the start position to the new path list. Then we see what direction you go to get to the next node. We keep looping until the direction to get to the next node is not approximately the same as the last direction (just do an epsilon comparison of the direction vectors, a straight equal could work but feels scary because floats). If you hit one that the next nodes direction is not the same direction as arriving, include the node in between those changes. At the end add the end node to the list. Now you have just the turning points in this new list.
find the closest 1 adjacent square to the target by calculating distance
check if that square is blocked, back to step 1 if it is
otherwise, move to that square and back to step 1 again
Step 1 is very customizable and is where you should do all your logic checks to filter out blocked squares or even path preference.
If the direction from the target is a perfect 45° diagonal, meaning 2 closest squares simultaneously, then make a priority list for the 4 directions to decide.