<img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/source-default-000.png" border="0"><img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/obstacle-default-000.png" border="0">
<img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/arrow-default-000.png" border="0"> <img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/arrow-default-000.png" border="0"> <img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/arrow-default-000.png" border="0"> <img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/images/dest-default-000.png" border="0">
<center><font size="6"><font color="red">- THIS BEHAVIOR IS NOT SUPPORTED ANYMORE, PREFER USING THE OFFICIAL ONE -</font></font>
The official pathfinding manual entry</center>
The rest of this posts stays for legacy purpose, but if you are a beginner/newcomer/first time pathfinder user just go away now and stick with the official behavior/documentation. Pathfinding examples are provided with your Construct2 installation in the folder "examples".
A pathfinder allows you to find the shortest path between a source and a destination, while avoiding obstacles on a map.
Check this demonstration which also acts as the pathfinder's documentation.
You can download the example .capx (it is fully commented)
You first need to have a copy of the behavior in your C2 folder before being able to load the .capx
And for your pleasure the Pathfinder behavior itself.
Unzip the content of pathfinder.zip in:
(it should create a 'pathfinder' folder and the files should sit nicely in there)
You can also find a new example showing you how to move an object with the pathfinder behavior.
This example is available here
Here also come an example allowing you to display "in real time" the possible path the unit might take. Get it here now.
Have fun finding paths. <img src="smileys/smiley2.gif" border="0" align="middle">
Important note about the usage of the PathFinder
Now the PF boards is accurate with the setting of the obstacles, no matter what their size is, as long as you respect the square grid aspect in your level design.
<img src="http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/r75-inprogress.PNG" border="0">
Quick image to show, the blue "mask" represents what the PF knows as "unwalkable" squares. The red sprite is the player.
You can see the first wall on the top left has a "double" mask compared to the other obstacles.
It's because of its position.
The CSS (Cell's Side Size) there is 32. And the wall's position happen also to be 32, meaning it sits on the edge of 2 squares.
And so it will appear as your sprite is avoiding the wall when it seems it should walk right next to it.
So if you respect the positioning of the obstacles in your level designs, it will work as intended (the rest of the blue masks).
11-09-2011: Reuploaded PFDemo.capx and the C2runtime.js from the demo to fix a bug in the drag/drop method (When dragging Source on Destination, Destination also get picked as to be dragged/dropped. And vice versa.)
13-09-2011: Reuploaded PFDemo.capx and the C2runtime.js from the demo to fix a bug when clicking the GUI panel button, if the panel was showing/hiding and/or the commands fading in/out.
Update to the PathFinder behavior runtime itself (setCellSizeSide). It appeared that the PathFinder was looking for a path out of the layout boundaries.
09-01-2012: Update to the PathFinder Behavior: corrected bugs concerning the cleaning of the ObstList and the bounding boxes of obstacles. If you had prior troubles with having several obstacles, this should now be fixed, and you should be able to place/use obstacles far more easier.
Fixes thanks to Yann.
Moving the object with pathfinder behavior thanks to Yann & myself.
16-01-2012: Update to the PF behavior. Fixing of all previous bugs, fixing of the obstacle recognition (wasn't good enough yet). Fixing of the moving example and addition of the moving with preview example.