ClosestPointOnNode is broken?

Hi. I found method “ClosestPointOnNode” and seems it’s broken? Variable “p” is never used after assignment. I thought that this method should return closest point to “p” on node in world space coordinates. Or I’m wrong?

Assets/AstarPathfindingProject/Generators/NodeClasses/GridNode.cs

		public Vector3 ClosestPointOnNode (Vector3 p) {
			var gg = GetGridGraph(GraphIndex);

			// Convert to graph space
			p = gg.transform.InverseTransform(p);

			// Nodes are offset 0.5 graph space nodes
			float xf = position.x-0.5F;
			float zf = position.z-0.5f;

			// Calculate graph position of this node
			int x = NodeInGridIndex % gg.width;
			int z = NodeInGridIndex / gg.width;

			// Handle the y coordinate separately
			float y = gg.transform.InverseTransform((Vector3)position).y;

			var closestInGraphSpace = new Vector3(Mathf.Clamp(xf, x-0.5f, x+0.5f)+0.5f, y, Mathf.Clamp(zf, z-0.5f, z+0.5f)+0.5f);

			// Convert to world space
			return gg.transform.Transform(closestInGraphSpace);
		}
1 Like

Wow. Yes that was indeed broken.
That method was only used in a single place and was used only in some rare scenarios.
I have uploaded a fix for it in a beta version (4.1.14, see https://www.arongranberg.com/astar/download).
Try that one and see if it works.

1 Like

I checked new version, fixed method working good now. Thanks!

p.s.
I think topic should be closed or archived, but I don’t know how to do this.