dooart [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=37664 Non-grid pathfinding experiment <p> <table><tr><td> <a href="/bbs/?pid=65235#p"> <img src="/bbs/thumbs/pico8_dooart_pathfinding-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=65235#p"> dooart_pathfinding</a><br><br> by <a href="/bbs/?uid=37664"> dooart</a> <br><br><br> <a href="/bbs/?pid=65235#p"> [Click to Play]</a> </td></tr></table> </p> <p>I couldn't find any pathfinding example for pico-8 that could be used for non-grid movement, so I took <a href="https://github.com/morgan3d/misc/blob/master/p8pathfinder/pathfinder.p8">this one</a> and built on top it.</p> <p>The necessity came when I started writing a game that had fluid movement inside a grid map (so rather than moving one tile at a time, the characters move one pixel at a time). Even with a tile-based map system, the collisions still had to be checked again for every pixel.</p> <p>This cart visually shows how the pathfinding works:</p> <ul> <li><strong>Yellow squares:</strong> path found with the grid pathfinding.</li> <li><strong>White line:</strong> path to the next grid tile, found with the pixel pathfinding.</li> </ul> <p>You can move one of the characters using the arrows. By pressing X, you can enable/disable the visualization.</p> <p>Tiles: <a href="https://thkaspar.itch.io/micro-tileset-overworld-dungeon">https://thkaspar.itch.io/micro-tileset-overworld-dungeon</a></p> <hr /> <p>The strategy is:</p> <ol> <li>Use A* at a tile grid level for long-distance pathfinding to find the shortest path to the target.</li> <li>Get the closest tile to the character from the shortest path.</li> <li>Use A* again at a pixel level to find the pixel path to that tile.</li> </ol> <p>Of course it'd be possible to use A* at a pixel level for the whole path, but pico-8 limitations would be hit pretty quickly on a large map with many characters.</p> <p>I thought I'd post it here to help the next person who needs something similar.</p> https://www.lexaloffle.com/bbs/?tid=34531 https://www.lexaloffle.com/bbs/?tid=34531 Sun, 16 Jun 2019 22:26:07 UTC