This is a system I'm working on for a game but I thought I'd share it.
Latest Version!
It is not finished but is nearly there so I thought I'd share it and get some feedback. I just have to do a reverse search which will find a quicker route in some circumstances.
What does it do?
It allows you to create a set of waypoints either automatically or by inserting waypoints where you need them. Then you can use the "find_path" function to find the fastest route between any two points.
The fastest route is stored in an array which you can then read to get the route for your characters.
Currently the search takes less than 2ms on my machine so I'm thinking lag will be minimal.
Commands
init_waypoints:
This initialises some global variables. Some code still needs to be moved in here...
create_rect_obstacle(x#,y#,width#,height#,angle#)
Adds a rectangular obstacle (currently all obstacles are visible but I'll be adding a method to hide / show debug images later) and all the necessary waypoints needed to get around it from any angle
create_obstacle(x#,y#)
is a 'random' rectangle creator and the predecessor of the previous command, used for testing
add_waypoint(x#,y#)
Manually adds a waypoint into the system
calculate_waypoint_nodes()
Works out the closest 8 waypoints to every other waypoint and stores it (and the distance to it) as a 'node'. This data is used to calculate fastest routes later. Also any waypoints that clash with other scenery objects are deleted.
show_waypoints() /
hide_waypoints()
This will be hidden in the debug code later
find_path(x1#,y1#,x2#,y2#)
This is the command used to calculate the fastest route between two points
If you plan on manually adding scenery it should be in physics group '2'...
Attached is the full code and a working test project.
I will be updating this source code as it improves.