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);
}