Lightning fast 2d pathfinder script?

Hi,

I’m looking for a replacement of my pathfinder script (2d only). Its too choppy on my iPhone 2g. The script can be really simple. I want to define a maze of, lets say 128x128 points, then define the blocked coords (e.g. x34, y66 is blocked) and the script should find a way from p1 to p2 around the blocked points. But it needs to be fast. All the script’s I have found so far a totally overloaded with features…what makes them slow in the end. The now used c# script works fine on a 3gs but I’ve to wait half a second on a 2g. :frowning:

Thanks!

Potentially your pathfinder isn’t the problem but your 16k fields within which you search.
128x128 isn’t a small search domain and you can likely speed it up quite a bit if you restrict the search to some reasonable surrounding (for example the amount of fields that can be seen on the screen)

Algorithmwise, I assume you use A*? If thats the case there isn’t a faster algorithm to solve the problem.

I have written a pathfinder algorithm that splits up the search over multiple frames. You can set the amount of nodes it searches each frame.
It works with nodes but you can lay them out in a grid off course.
It was originally written in ActionScript and then I translated it to C#. It hasn’t been thoroughly tested but it should do the trick.

Don’t have the time to cook up an example of how to use it atm. Let me know if this works for you.

EDIT: I’m not sure, but I think the way it’s set up right now it will do an allocation each time you do a search, this was written before I started looking into GC optimization, so maybe you’ll have to be careful with that.

318740–11235–$pathfinder_429.zip (3.73 KB)

Thanks to booth of you! I tried lowering the maze resolution now (yes, it’s A* algorithm, I did this at first in Actionscript as well :)) and bingo…smooth like silk. Mmhh, I might have guessed that.