I’ve been slowly working on the foundation of my second game, one that makes use of a multidimensional array of ‘tile’ planes to interact with the mouse, allowing the player to click to move units to them. So far I’ve got it checking the adjacent squares, so the player can move one square at a time (like the King in Chess), but obviously I’d like to have them moving further, until they run out of ‘movement points’.
I’ve been reading different guides to pathfinding, some theory (like A* Pathfinding for Beginners) and some code examples , but writing such a system is pretty daunting obviously, but I think I could tackle it if I could see how others have written theirs for tile-based systems, not nodes. I’m working with JS, if that’s relevant.
Does anybody know of any resources for/examples of JS Tile-Based pathfinding?
Thanks. I’ve been reading this since I posted this morning , which looks pretty spot-on. I’m looking just to build a basic, fundamentals-only system and then add the specifics my project will need piece-by-piece.
That’s a good one too. There are some strong, simple-to-understand implementations of A* in JavaScript/JScript out there if you poke around. This is another one that I know a friend swiped for one of his Flash games almost verbatim, even though the code is specifically for HTML: http://stormhorse.com/a_star.js
I swear that nodes, acyclic directed graphs, heuristics and other terminology are thrown around by people just to be confusing. Grids, nodes, hexagons, planetary bodies or worm holes, it all means the same think to A*. Once you realise what A* and many other algorithms of its ilk actually are, you can use them for more than just searching for the optimal path between two points. You can use A*-like algorithms, and the underlying basis of A* or Djikstra, to find paths, search for words (though there are better solutions too such as an actual acyclic directed graph), plan optimal build trees for an AI in an RTS, plan optimal progression through a technology tree in an RTS, and so on.
A robust, generic A* algorithm for searching on a grid can be implemented in less than 50 lines of code given a reasonably “modern” language, such as C# or JavaScript, with good data structures built in to the language.
You might want to check out this. A* Pathfinding. And i think searching forums might be more useful than lmgtfy. Actually i know of one that uses tile. Sort of. It’s paid though. Simple Path. I have never attempted pathfinding yet so i just post what i know.