Any-Angle Pathfinding 2 (Top Down) (No Waypoints!)

49
50
0
1

A better version of Any-Angle Pathfinding can be found here:
https://flowlab.io/game/play/2507823


Level 1: Left Click to move the Target around.


Level 2: Hold Right click to move the Player towards the mouse.


All the pathfinding is calculated and stored in the target and a single brain object.


To copy this into a game, make sure that the brain object is the LAST object placed in a level. That means if you ever edit another object in the level by clicking on it (even if you don't move it), you MUST delete the brain object and then add it back. (This is due to the order in which Flowlab triggers objects' code.)


The delay at the beginning is intentional; it gives the map a chance to calculate its boundaries and each obstacle a chance to find its position ID. The map boundaries only extend a block outside the furthest wall, so if you click beyond that, the pathfinding won't work. But the boundaries can be changed arbitrarily, so you could set them to be further out if you wanted to.


Some of the walls delete / re-add themselves to show how this can work with a dynamic, changing map.

Editor