Tutorial: Pathfinding in two lines
So you need no-nonsense pathfinding and fast? Not a problem. This brief tutorial explains how to interface with Path from your code as simple as possible.
Prerequisites:
- The Path package has been imported into your project.
- You’ve set up some waypoints and connected them in the editor. If you’re not sure how to do this, please check out the video on the documentation page.
- To handle your pathfinding, you’ve created a script file and attached it to the same GameObject as your Navigator component.
Ok, here we go. Hang tight.
- In your MonoBehaviour script, where you want to initiate pathfinding to some point (in my case I’ve stored the point in a Vector3 variable named myDestinationPoint), add the following line:
GetComponent<Navigator> ().targetPosition = myDestinationPoint;
- Somewhere in the same script or another script attached to the same GameObject, add the following line:
public void OnNewPath (Path path) { Debug.Log ("Path: " + path); } - Put on a nice tune and make a kick-ass game!
Remember to check out the Path class documentation for all the different data points available, waiting to be connected up with your path following code.
More tutorials to come!
What do you mean by “The Path package should be imported to the Project. ” This may seem trivial. But I am not getting it. A sincere question. And I am new to Unity3D.
–
Venktesh.