Pathfinding 4: Even More Optimized (Top-Down, No Waypoints, Multiple Targets)

118
119
0
1

[WSAD / Arrow Keys / Hold Right Click] to move

[ + / - ] to zoom in / out

Press [Backtick / Tilda] to toggle a view of the Waypoints

Press [P] to pause / unpause the game

Press [F] to toggle fullscreen on / off

[Left Click] any blue Player to destroy it

[Left Click and Drag] any orange Enemy to move it

[Left Click and Drag] any light gray Wall to move it

[Left Click] any dark grey Wall to toggle it on / off (also you can click and drag over them to toggle them)


Standard Breadth-First Search (BFS) pathfinding using lists (no extra waypoint objects are needed). This allows multiple enemies / allies to find and follow the shortest path to the closest target object (the blue Players in this case)

I could try to further optimize this by implementing a queue using this idea (suggested by grazer; thanks again!)

https://en.wikipedia.org/wiki/Circular_buffer


Features:

-very fast performance (you could actually add this to a game and have it still be playable)

-multiple targets and followers

-moveable / destroyable obstacles, targets, and followers

-dynamic map boundaries (you can go out of bounds and the pathfinding still works)

-simplified code that is easier to modify


Questions and Feedback:

https://community.flowlab.io/t/4-pathfinding-player-follow-examples-platforming-top-down/36367/28

Editor