2D Toolkit Forum
2D Toolkit => Contract Work => Topic started by: dotty on March 17, 2013, 03:53:53 pm
-
Hello all.
I've been trying to implement pathfinding using 2dtk's tilemap system and I'm failing miserably. I've tried to write one myself (and failed) and I've tried to implement arongranberg 's aStar plugin (and failed). I'm getting frustrated, so if anyone would be interested in doing this for me, I'm sure we could come up with a fair price.
If you're interested, drop me a PM.
Just a couple of needs.
1) The package needs to scan through ALL layers and find collidable tiles.
2) Needs to be lightweight and quick
3) Needs to support quite large maps 512x512
4) Needs to support multiple tile sizes (32x32, 64x64, etc)
5) Only needs orth tiles (no need for iso tiles)
6) Ideally collision arrays need to be saved so they don't get created on runtime.
I think that's about it at the moment, again if you're interested drop me a PM.
-
I would be highly interested in this too,,,on a side scroll basis.
-
Hi there,
I just got here and will check 2dtoolkit out tonight.
I think this (https://github.com/krazyjakee/jQuest/blob/master/src/astar.js (https://github.com/krazyjakee/jQuest/blob/master/src/astar.js)) is what you're looking for, however, I haven't integrated it into 2dtk yet. Give me some time and I'll let you have it.
-
Whatever happened to this thread, I would love to know whether anyone ever found a solution to get pathfinding working with tk2d tilemaps.
-
I got it working with Simple A* (http://forum.unity3d.com/threads/164003-Released-BFGames-Simply-A*-Pathfinding!) if you're interested?
-
I am indeed and curious to see how you did it.
I have done some experiments too with simple A* but wasn't satisfied with the result. One of my main problem is that my tilemap is huge (930x326 tiles) with a tileset of 512 different tiles. I am trying to avoid generating colliders or prefabs for each and every tile.
-
I ended up editing simple a* to run my own method a create an array of nodes. I essentially looped over ever tile, if it had a collider mark it as unwalkable, if it doesn't mark it walkable. I then pumped that array into simple a* and let it run it's own pathfinding. It worked well for me. I had a map about 100x100 tiles, each tile being 32px X 32px. I had about 50 pathfinders running without a hitch. This was on i7 retina macbook pro.
I'll send the code across later when I get home from work.
-
Thanks, that's very interesting ! I'm looking forward to see how you did that.
-
Obviously import simple A *, then create a script called PathFinder2DTileMap.cs and add the code in the link below.
All you need to do is set Toolkit2DTileMap to a tk2dTileMap object and it should do the rest (if you click "Draw Map In Editor", you'll see the red areas that aren't walkable, and green which are).
You can then use simple A *'s Pathfinding functions. Be warned, this script was created for a 32x32 tile, and simply selects tiles if they have a collider or not, so you might need to tweek it a lil.
http://pastiebin.com/51d7253305569
-
Many thanks ! I'll try that as soon as i get back.
-
I'm trying this, and it returns all of my tiles as having an ID of -1. Any ideas?
-
-1 implies the tile has no collider.
However, I know the tilemap api/system has been recently updated, so the code might need updating. I'll take a look at it over the weekend and try to update it as soon as possible.
Do you have multiple layers? That could be the issue here.
-
The API update shouldn't have affected that, I don't think - it still returns / stores the same values.
-
For some reason, I can't get the Draw Map in Editor option to work.
Ok, you have to look at the editor window while the game is running.
-
It doesn't seem to be 100% accurate. Walkable nodes will still connect to non-walkable nodes like this (the gray walls have colliders on them):
(http://i.imgur.com/a1q6WNg.png?1)
I'm trying to figure out why but has anyone else encountered this problem?
-
is this doing some kind of graph traversal at run-time?
do you have any dynamics that aren't just switching the collision on and off on a tile? you could cache everything offline as some kind of 'potential reachability set' data and partition the world up so that tiny little numbers like 4k x 4k are no longer scary but trivial to handle quickly... dealing with this kind of data efficiently can be slightly painful if you have a very large grid, but the combination of hierarchy and clever use of memory can help there - although given how much Unity consumes when it does nothing its probably not worth bothering with that until you confirm that you really have a memory problem first. :)
has this been adequately solved yet? i'm kind of curious just out of interest rather than any desire to make this for money - this is pretty standard games/AI programmer stuff so in theory it should be easy to solve with help from the internet - in practice I know that a lot of this stuff is pretty poorly documented in terms of practical implementation details.
(I'd do it, but I have a full-time job and I'm very expensive - I'd feel rude just to ask for even 10% of my usual rate from an indy).
-
It doesn't seem to be 100% accurate. Walkable nodes will still connect to non-walkable nodes like this (the gray walls have colliders on them):
(http://i.imgur.com/a1q6WNg.png?1)
I'm trying to figure out why but has anyone else encountered this problem?
I have run into this problem as well, did you ever find a resolution for this?
-
Just a follow up to this. I spent a lot of money on different a* solutions, and the best, by far, was http://arongranberg.com/astar/ .
There's a free version, but I opted for the pro versions ($100) as I'll be able to apply it to more situations (both 3d, and 2d).
The latest version of A* works with BoxCollider2D which is perfect! However, there's 1 downfall. When you create a tilemap with TK2D it create it's colliders using EdgeCollider2D. It uses EdgeCollider2D as it reduces the amount of PolygonCollider/BoxColliders needed. So basically you need to manually draw all the BoxCollider2D's for each 'solid' tile, then get the A* to generate a grid.
If your tilemaps have a consistent tilesize (32x32 64x64, etc) and each tile is either collidable, or not, then you can use my super handy UnityEditor plugin to automatically loop through your tilemap and place a BoxCollider2D in it's place.
https://github.com/kevdotbadger/BoxColliderGenerator
-
http://i.imgur.com/8ItpwUw.png
http://www.gfycat.com/ActualCrazyAtlanticblackgoby
https://gist.github.com/rakkarage/c0b304dfd8023f672870
-
(http://i.imgur.com/a1q6WNg.png?1)
I'm also having this problem when attempting to follow Dotty's script. Can anyone think of a solution to this? Or another pathfinding solution that will easily work with a 2dtoolkit tilemap?
-
check out that code & pics i just posted... a simple astar that works with 2dtoolkit
it will need to be reworked a bit for individual games i guess but
(http://giant.gfycat.com/ActualCrazyAtlanticblackgoby.gif)