2D Toolkit Forum

2D Toolkit => Contract Work => Topic started by: dotty on March 17, 2013, 03:53:53 pm

Title: [paid] Tilemap pathfinding
Post 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.
Title: Re: [paid] Tilemap pathfinding
Post by: x8105 on April 24, 2013, 09:03:50 am
I would be highly interested in this too,,,on a side scroll basis.
Title: Re: [paid] Tilemap pathfinding
Post by: jakecattrall on May 21, 2013, 03:11:49 pm
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.
Title: Re: [paid] Tilemap pathfinding
Post by: pythagoras123 on June 28, 2013, 12:41:37 am
Whatever happened to this thread, I would love to know whether anyone ever found a solution to get pathfinding working with tk2d tilemaps.
Title: Re: [paid] Tilemap pathfinding
Post by: dotty on July 03, 2013, 11:37:10 pm
I got it working with Simple A* (http://forum.unity3d.com/threads/164003-Released-BFGames-Simply-A*-Pathfinding!) if you're interested?
Title: Re: [paid] Tilemap pathfinding
Post by: pythagoras123 on July 04, 2013, 12:20:34 am
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.
Title: Re: [paid] Tilemap pathfinding
Post by: dotty on July 05, 2013, 10:03:37 am
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.
Title: Re: [paid] Tilemap pathfinding
Post by: pythagoras123 on July 05, 2013, 04:50:59 pm
Thanks, that's very interesting ! I'm looking forward to see how you did that.
Title: Re: [paid] Tilemap pathfinding
Post by: dotty on July 05, 2013, 09:05:06 pm
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
Title: Re: [paid] Tilemap pathfinding
Post by: pythagoras123 on July 06, 2013, 01:33:47 pm
Many thanks ! I'll try that as soon as i get back.
Title: Re: [paid] Tilemap pathfinding
Post by: JBabz on August 22, 2013, 06:15:45 pm
I'm trying this, and it returns all of my tiles as having an ID of -1. Any ideas?
Title: Re: [paid] Tilemap pathfinding
Post by: dotty on August 23, 2013, 12:22:39 pm
-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.
Title: Re: [paid] Tilemap pathfinding
Post by: unikronsoftware on August 23, 2013, 12:43:30 pm
The API update shouldn't have affected that, I don't think - it still returns / stores the same values.
Title: Re: [paid] Tilemap pathfinding
Post by: Artheus on November 14, 2013, 07:32:39 am
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.
Title: Re: [paid] Tilemap pathfinding
Post by: Artheus on November 15, 2013, 11:07:46 pm
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?
Title: Re: [paid] Tilemap pathfinding
Post by: semiessessi on January 03, 2014, 12:23:53 pm
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).
Title: Re: [paid] Tilemap pathfinding
Post by: hektac on February 27, 2014, 11:20:21 pm
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?
Title: Re: [paid] Tilemap pathfinding
Post by: dotty on March 13, 2014, 03:36:42 pm
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
Title: Re: [paid] Tilemap pathfinding
Post by: rakkarage on June 04, 2014, 01:34:54 am
http://i.imgur.com/8ItpwUw.png
http://www.gfycat.com/ActualCrazyAtlanticblackgoby
https://gist.github.com/rakkarage/c0b304dfd8023f672870
Title: Re: [paid] Tilemap pathfinding
Post by: zeteginara on June 20, 2014, 03:57:07 am
(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?
Title: Re: [paid] Tilemap pathfinding
Post by: rakkarage on June 20, 2014, 04:30:52 am
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)