I am working with the Aron Granberg AStar Pathfinding asset, using the grid graph. Right now when I click on a target (like a monster) my player moves to the same node as the target, thus being on top on the target. What I want is to stop the player moving 1 node before the target, the adjacent node that would be closest to the player. The code that I have found looks something like this:
if (Physics.Raycast(ray, out hit))
{
Interactable interactable = hit.collider.GetComponent<Interactable>();
if (interactable != null)
{
GraphNode nearestNode = AstarPath.active.GetNearest(gameObject.transform.position, NNConstraint.Default).node;
if (nearestNode.Walkable)
{
Int3 a = new Int3();
Vector3 b = (Vector3)a;
ai.destination = b;
}
}
}
the whole GraphNode line gets the node (I think) but I am not sure how to translate that into the code just below that. I am not even sure if this is the right code to be using. Does anyone know how to make this work?