"go" Unity comes with pathfinding Navmesh Getting Started tutorial (i)

Source: Internet
Author: User

http://liweizhaolili.blog.163.com/blog/static/16230744201271161310135/

Description: from today, I Zhao intends to write some simple tutorials, to facilitate their own future review, or to facilitate the newly-started friends to Learn. Don't be offended by the limited level. however, Please respect the work of the Code-word recorder, if you need to reprint please tell me First. Thank you!

Unity has added Navmesh pathfinding functionality since the 3.5 release. Until then, unity users could only do pathfinding through Third-party plug-ins, such as the Astar pathfinding plugin. Zhao I also used a * search plug-in, A * principle is not complex, interested friends can own Baidu a bit. however, because it is not the function, so in the setting grid and baking process will inevitably cause a lot of inconvenience. Navmesh is a feature of unity, and there are many similarities between the usage and the previous lightmapping baking or occlusion culling occlusion culling.

This feature has a lot of interesting places, and it is very convenient to use, I intend to separate several logs to introduce Each. The purpose of this time is simply to understand the basic usage of navmesh, so temporarily do not detail the meaning of each parameter and function of the translation Component.

Let's take a look at how to open the Navmesh function window in unity:

In the window Drop-down list you can see navgation, click:

The navigation panel appears next to the original Inspector Panel: This OBJCET panel is the object to be selected before, and the bake panel next to it corresponds to the global Option. The structure and baking or occlusion culling are the Same. When the object is selected, the above content will appear: all above, meshrenderers, Terranis is a filter filter for the selection of items displayed in the Hirarchy panel: all is the display of all meshrenderers is only a rendered mesh object and terrains of course only shows the terrain Object. The following is an important option, the first navigation static option is to select whether the object is part of the pathfinding Function. The other options below are only available if this option is Checked. The offmeshlink generation option is to choose whether the object automatically generates offmeshlink based on the global options of height, jumping broadband, and so on, which is explained in detail in a later explanation, and is not discussed for the time Being. The Navigation layer is a classification of map objects that participate in the pathfinding function, which is categorized by layers, with the default of three layers to choose from, and of course you can add layers Yourself. Old version: in the edit drop-down list, Select Project--navmeshlayers Note: After 4. A few new versions, the location of this pathfinding management Open has changed to become in the navigation  panel inside the:  appeared navmesh layer of management interface:  above three buit-in Layer is the default three optional layer of the system, we can enter the name of the layer we need in the user layer below, for example, I now input a layer called "brigde"   this time, the "bridge" layer just entered, it will appear in the list of selectable   Through just a few steps, Navmesh commonly used several panels we have already operated, next can do a small example:  in the scene, I put a camera, a patch of ground (plane), A character model (man) and a target point object (target) to make it easier to observe the position of the target point, I added a light component to the object to give it a glow. The Navmesh component must be added to the character model (man), otherwise it will not be possible to find a way. For convenience, I used the official soldier model, which already had a script with animated and animated Controls. however, the performance of these animations is not important for the time being, you can choose to put a capsule or cube instead of the character model.   Remember the navigation panel you just started? Select the ground (plane), in the navigation panel inside the check navigation static option, the other default does not Change. Then click on the Bake panel in the lower right corner. At this time there will be a calculation process, once used baking or occlusion culling of friends should be familiar with the Process. however, As with the previous two functions, if you do not save the scene level,unity will prompt you to save, and then Bake. Since there are few objects in the scene, the bake process is soon over. Watch the scene window, now the color of the ground has changed, this is because unity has helped you to generate the Navmesh grid, because there is no blocking the barrier, so the entire ground is a walking range. Write one of the simplest control scripts, the above is C #, because it is very simple, the estimated use of JS friends can also write the Corresponding. Simply explained, the script is directly dragged onto the character (man) and the target object in the scene is dragged and dropped to assign to the Script's target Variable. At the beginning of the script, I   acquired the Navmeshagent Script component of man, and in the process of update, the man constantly took a path to the Target's displacement and moved to the location of the Operation.   inAfter you've done this, you should already be able to click on the Unity play button and move the target object, and the character model is ready to run after the target Point. Here I also made a simple mouse click plane set the target point function, because this function is not within the scope of the discussion, so interested friends can go to Baidu a specific method.   to this step, the characters have run up, but because there is no blocked obstacles, so the characters will just walk straight, can not see the feeling of seeking the Road. Next we do something more complex: in the scene to add a cube as an obstacle, the specific shape and position according to their own liking to adjust, Zhao I was to make it a rectangle, and placed in front of the Character. And the operation of the ground just about, select the block cube, in the navigation panel check navigation static option, this time the navigation layer to choose not walkable. As the name implies, this is not the meaning of walking, representing the cube can not be passed. After the selection is complete, we click Bake again, a small waiting process. When the bake is complete, we return to the scene window.   Watch the scene window, you will find that the entire ground is navmesh, the situation has changed, around the obstacles, Navmesh left a gap, which means that the role can not be passed from the Obstacles.   Click Unity's Play button again now, we can see that the character has been able to go around the obstacles, our purpose has been successfully achieved.         This is the end of the Example.       in the second section, I will explain in detail the high and low falls, climbing ladders and jumping and other more complex features. then, in the third section, we will explain the sub-conditional pathfinding (different people taking different paths), and the functions of dynamic control roads (such as drawbridge).       the first time to write a tutorial, there may be some less humane places, please understand.       again, Please understand the author's hard work, if necessary to reprint, please inform me, I am Azhao, thank you!   

Go "unity comes with pathfinding Navmesh Getting Started tutorial (a)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.