Hello Guest

Author Topic: Has anyone used astar pathfinding with tile map?  (Read 5963 times)

dotty

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 65
    • View Profile
Has anyone used astar pathfinding with tile map?
« on: March 10, 2013, 03:59:02 pm »
I'm having trouble getting this working. The astar pathfinding unity plugin (http://www.arongranberg.com/astar/docs/index.php) the free version.

Has anyone used these together?

dotty

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 65
    • View Profile
Re: Has anyone used astar pathfinding with tile map?
« Reply #1 on: March 12, 2013, 09:18:07 pm »
Just an update on this. I got it working!

I created a gameObject and wrote a script which takes a tk2dTileMap object and a AstarPath object and did something like this...

Code: [Select]
// Get the tilemaps' collider layers' mesh
Mesh mesh = mapData.Layers[1].GetChunk(0,0).colliderMesh;

// Create a new mesh graph
NavMeshGraph newMeshGroup = new NavMeshGraph();
newMeshGroup.sourceMesh = mesh;

// Add it
aStar.astarData.AddGraph( newMeshGroup );


cquinones

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Has anyone used astar pathfinding with tile map?
« Reply #2 on: May 16, 2013, 12:21:52 am »
Isn't the NavMeshGraph expecting the "walkable" area? If so, how is this working for you? I've defined colliders for the wall sprites, which would imply that these are the areas you can't pass through. If I'm not mistaken, this won't generate an area that the pathfinding objects can walk on.

Am I missing something here? If anyone else would like to comment on how to build a navigation mesh out of tk2d tile map data, I would greatly appreciate it.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Has anyone used astar pathfinding with tile map?
« Reply #3 on: May 16, 2013, 09:49:05 am »
You can simply add a ground plane for that.
The important thing is to use the mesh collider as dotty  instead of the render mesh - the render mesh which Unity uses by default is flat (as it is a sprite), and unusable with the navigation system.

Artheus

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Has anyone used astar pathfinding with tile map?
« Reply #4 on: November 13, 2013, 10:50:54 pm »
Has anyone got this working with the grid graph?