I made a few surfaces and a few agents, then when I wanted to make a couple more the old navs and new ones just stopped working it says it only works if you place navmesh on a land but that doesn't work, Im using 2020.3.11v of unity. Thanks.
Radius of the Agent is 0.5 not that small Height of Agent = 2 Step Height of Agent = 2 etc all are normal. And yes I enables gizmos, none of the things in google helped.
CodePudding user response:
never mind turns out it was a glitch
CodePudding user response:
- To use a navigation system, first build a navigation mesh for the scene: (1) Select the scene geometry that should affect navigation: walkable surfaces and obstacles. (2) Since baking is an advance operation, to make the baked object tick static, check the Navigation Static checkbox to include the selected object in the navigation mesh baking process.
(3) Adjust the bake settings to match the proxy size. (4) Click Bake to build the navigation mesh. In navigatior - Agent Radius defines how close the agent center is to the wall or window sill. - Agent Height defines how low the agent can reach. - Max Slope defines how steep the agent will go up the ramp. - Step Height defines the height of obstacles that the agent can step on.
(5) After the baking is completed, the navigation mesh resource file will be found in a folder with the same name as the scene to which the navigation mesh belongs. For example, if you have a scene called First Level in the Assets folder, the NavMesh will be located in Assets > First Level > NavMesh.asset. (6) The NavMesh Obstacle component can set non-static objects as obstacles, which will be automatically bypassed during navigation (7) The Off-Mesh Link component can create a channel that can jump between two disconnected navigation meshes
Scripting Using the navigation system, you can first obtain the NavMeshAgent component, such as assigning it to the variable agent, and use agent.destination =position to set the navigation end point. Click to Navigate
public class NavClick : MonoBehaviour { private NavMeshAgent navMeshAgent; private void Start() { //Get the navmesh proxy component navMeshAgent = gameObject.GetComponent<NavMeshAgent>(); } private void Update() { if(Input.GetMouseButtonDown(0)) { //ScreenPointToRay can create a ray starting from a point where the camera enters the clipping plane. The reverse extension of this ray passes through the camera, and the ray can be uniquely determined by these two points Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //The corresponding parameter of Raycast is the ray, the returned object information, the ray distance if(Physics.Raycast(ray,out hit,float.MaxValue)) { //Assign the returned collision point to destination navMeshAgent.destination = hit.point; } } } }
This is a simple unity navigation, which includes the establishment of the navigation system, scripting, and the use of navigation, I hope it helps