All my scripts find the correct vector3 position for both the start and end position however when the nodes to use for these positions are calculated they always seem to be offset by 5 nodes in the z direction.
I have checked the maths and it all works out, yet the incorrect nodes are still calculated.
public Node NodeFromWorldPoint(Vector3 worldPosition) {
float percentX = (worldPosition.x + gridWorldSize.x/2) / gridWorldSize.x;
float percentY = (worldPosition.z + gridWorldSize.y/2) / gridWorldSize.y;
percentX = Mathf.Clamp01(percentX);
percentY = Mathf.Clamp01(percentY);
int x = Mathf.RoundToInt((gridSizeX-1) * percentX);
int y = Mathf.RoundToInt((gridSizeY-1) * percentY);
return grid[x,y];
}
The error must be in here yet after days and days of working on this one issue I can’t find it.
Any ideas would be greatly appreciated.