Log In  

Cart #dooart_pathfinding-0 | 2019-06-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
14

I couldn't find any pathfinding example for pico-8 that could be used for non-grid movement, so I took this one and built on top it.

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.

This cart visually shows how the pathfinding works:

  • Yellow squares: path found with the grid pathfinding.
  • White line: path to the next grid tile, found with the pixel pathfinding.

You can move one of the characters using the arrows. By pressing X, you can enable/disable the visualization.

Tiles: https://thkaspar.itch.io/micro-tileset-overworld-dungeon


The strategy is:

  1. Use A* at a tile grid level for long-distance pathfinding to find the shortest path to the target.
  2. Get the closest tile to the character from the shortest path.
  3. Use A* again at a pixel level to find the pixel path to that tile.

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.

I thought I'd post it here to help the next person who needs something similar.

P#65235 2019-06-16 22:26 ( Edited 2019-06-17 00:07)

Cool code though i seem to have implemented something incorrectly and it gives me out of memory cartridge attached

Cart #rokipikidi-0 | 2021-07-21 | Code ▽ | Embed ▽ | No License

P#95116 2021-07-21 01:23 ( Edited 2021-07-21 01:23)

good

P#95164 2021-07-22 01:15

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:19:07 | 0.014s | Q:22