2D Toolkit Forum

2D Toolkit => Support => Topic started by: andreasgan on January 17, 2015, 02:53:28 pm

Title: PolyNav with TileMap
Post by: andreasgan on January 17, 2015, 02:53:28 pm
Hey, I'm wondering how I can use polynav with 2d toolkit's TileMap

Polynav is a simple 2D pathfinding solution that uses polygon colliders/box colliders on obstacles.
http://forum.unity3d.com/threads/poly-nav-pathfinding-for-unity2d.224962/

I'm wondering how I can make my tiles obstacles with polynav.
Each "obstacle" object needs to have a BoxCollider2D or PolygonCollider2D, and a "PolyNavObstacle" script.

My tiles are all squared, and they are going to be changed/deleted ingame.
I was thinking I need to find the edges of all "islands" so to speak, and make seperate polygoncollider2ds from them.
Note: Using prefab tiles would create too many gameobjects.

How can I achieve this? It's been bugging me for a while and I can't figure it out.
I'm sorry if this was messy and hard to understand. I've never been good at explaining things :/
Any thoughts at all would be appreciated.
Thank you :)

EDIT: I'll be trying to modify the 2d toolkit code to use polygon colliders instead of edgecolliders. Not sure how yet, but I'll try.
Title: Re: PolyNav with TileMap
Post by: unikronsoftware on January 18, 2015, 10:54:03 pm
dotty posted some sample code here that uses polygon colliders
http://2dtoolkit.com/forum/index.php/topic,4582.msg21706.html#msg21706
Title: Re: PolyNav with TileMap
Post by: andreasgan on January 19, 2015, 11:09:37 am
Thanks, I already found that, but last time I checked his code made box colliders, and it wasn't very effective. No problem though, I already made polygon colliders; I just replaced EdgeCollider2D with PolygonCollider2D in all the files :)

There's some things I have to tweak to make it perfect though; tk2d creates an extra collider point for each path, and the polygon is inverted (points in wrong direction. But this isn't really a problem, polynav has a "invert polygon" feature)
I also have to add the polynav obstacle script to all chunks.
And lastly make sure all this works when I edit tiles and build.

I haven't had time to start diving into the code and fixing this yet, so if you got any tips I'd appreciate it :)
Title: Re: PolyNav with TileMap
Post by: andreasgan on January 28, 2015, 05:33:49 pm
Hello again,
I finally got this working fine, but when I started building a tilemap that is bigger than 1 chunk, I encountered this weird problem:

http://i.gyazo.com/f09e0f08e19ce3117bdc5f3233eb517d.png

I seriously can't figure this one out. Except the fact the colliders are all messed up, I have no idea what's wrong, or what's going on.

If you would be so kind as to help me with this, here's the code:
http://pastie.org/9868742
Thank you!
Title: Re: PolyNav with TileMap
Post by: radu on March 06, 2015, 05:39:39 pm
Any progress on this? I'm looking to replace astar with polynav as the paths look more believable, but it looks like this it's a bit more complicated than I first thought.