A* GetNearest() implementation

by ThePumkinMelon   Last Updated May 15, 2019 23:13 PM

I'm trying to implement pathfinding in my platformer and I'm having trouble coming up with a way to find the nearest node to a world point.


I tried this:

public Node GetNodeFromPoint(Vector2 point)
    {
        int xGridPoint = Mathf.RoundToInt(point.x / gridWorldSize.x);
        int yGridPoint = Mathf.RoundToInt(point.y / gridWorldSize.y);

        Debug.Log(xGridPoint + " " + yGridPoint);

        return grid[xGridPoint, yGridPoint];
    }

But it always gave me [0,0].



Related Questions


Updated February 26, 2019 16:13 PM

Updated September 12, 2016 08:05 AM

Updated June 17, 2017 15:13 PM

Updated May 11, 2019 05:13 AM

Updated June 02, 2015 14:05 PM