I know that A* Pathfinding retrieves the tile closest to the point I clicked on the grid. What I want is to change the color of the tile A* receives. How can I do that?
Hi
You can get the closest node to a point, when clicked, using AstarPath.active.GetNearest. How you display this information to the user in your game is up to you.
Yes. Physics2D.Raycast does not take a Vector3 for its direction. It takes a Vector2.
If you have a 2D game, you don’t need to raycast before calling GetNearest.
So what should I give as a parameter to GetNearest?
Probably something like:
var p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
p.z = 0;
GetNearest(p);
It worked. Thank you so much!
Ups It is not working.
Line 59, directly gives the position of the point I clicked on.
Line 60, gives the x position of the node closest to the position I clicked on.
I want something like in line 60. but it needs to give the return value as vector3 or vector2.
Is that possible?
You can cast a node position to a Vector3 using: (Vector3)node.position
.
Okay worked thankss!