Search Unity

A* pathfinding with Tilemap

Discussion in 'Navigation' started by Irgi, Feb 15, 2019.

  1. Irgi

    Irgi

    Joined:
    Apr 4, 2018
    Posts:
    5
    hi there
    i want to create A* pathfinding using this tutorials from sebastian lague using a unity 2d tilemap:

    the problem is when i move the seeker position.y up to -2, the node path seems to go down about 2 nodes.

    i've been modifying the NodeFromWorldPoint() method a little bit so the x coordinates seems to be good, but still have this problem from the y coordinates. here is the method code:
    Code (CSharp):
    1. public Node NodeFromWorldPoint(Vector3 worldPosition)
    2.     {
    3.         float percentX = (worldPosition.x + gridSizeX / 2) / gridSizeX;
    4.         float percentY = (worldPosition.y + gridSizeY / 2) / gridSizeY;
    5.         percentX = Mathf.Clamp01(percentX);
    6.         percentY = Mathf.Clamp01(percentY);
    7.  
    8.         int x = Mathf.RoundToInt((tileMap.size.x - 1) * percentX);
    9.         int y = Mathf.RoundToInt((tileMap.size.y) * percentY);
    10.         return grid[x-1, y];
    11.     }
    this is my first thread post, so i'm sorry for my bad english ^-^
     

    Attached Files:

    eschultz591 likes this.