What are the considerations related to unity automatic pathfinding
This article is to share with you what are the notes related to unity automatic pathfinding, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.
First select the terrain where the character is located, click window- > Navigation to open the Navigation window, select "Navigation Static" from the object tab under Navigation to keep the default, and then click "Bake" in the lower right corner. If there is an obstacle, and the obstacle does not belong to the terrain object, you need to bake the obstacle by selecting the obstacle, check "Navigation Static" in the Object tab under Navigation, "Navigation Layer" select "Not Walkable", open the Bake tab, modify the relevant parameters as needed, and then click "Bake" in the lower right corner to bake. For the role of auto-pathfinding, you need to add a "NavMeshAgent" component by clicking "component- > Naviga- > NavMeshAgent" in the menu bar so that the relevant settings for auto-pathfinding are completed; you also need to add code for the role so that he can automatically find the way:
Public PlayerControl:MonoBehavior
{
Private NavMeshAgent agent
Public float speed=6
Void Start ()
{
Agent=GetComponent (); / / get the NavMeshAgent component
}
Void Update ()
{
If (Input.GetMouseButtonDown (0))
{
Ray ray=Camera.main.ScreenPointToRay (Input.mousePosition)
RayCastHit hitInfo
If (Physics.RayCast (ray,out hitInfo))
{
If (! hitInfo.Collider.name.Equals ("Terrain"))
Return
Else
{
Vector3 point=hitInfo.point
Transform.LookAt (new Vector3 (point.x,transform.position.y,point.z))
Agent.speed=speed
Agent.SetDestination (point)
}
}
}
}
}
These are the matters needing attention related to unity automatic pathfinding, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.