Hello Guest

Author Topic: PolyNav with TileMap  (Read 7061 times)

andreasgan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
PolyNav with TileMap
« 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.
« Last Edit: January 17, 2015, 04:05:32 pm by andreasgan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: PolyNav with TileMap
« Reply #1 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

andreasgan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: PolyNav with TileMap
« Reply #2 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 :)

andreasgan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: PolyNav with TileMap
« Reply #3 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!

radu

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: PolyNav with TileMap
« Reply #4 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.