"Unity" 12.1 Basic concepts

Source: Internet
Author: User
Tags unity 5

Development environment: WIN10, Unity5.3.4, C #, VS2015

Date Created: 2016-05-09 I. INTRODUCTION

The navigation grid (Navmesh) is a simplified representation of the geometry in the world coordinate system and is used by the game agent for global navigation. Typically, an agent has a destination or a destination that attempts to find a path to that destination or destination, and then navigates to that target along that path, a process called pathfinding (path Finding).

Note that the navigation grid generation (or baking) is usually done in the editor by the game developer, and the pathfinding is usually done by the agent at run time based on the navigation grid.

In a complex game world, there can be many proxies and dynamic obstructions, and since these dynamic obstructions are constantly changing in different regions (areas) of the world's geometry, the agents need to react dynamically to these changes. In other words, an agent's pathfinding task may be interrupted or affected by something, such as avoiding collisions with other characters, changing terrain features at any time, dynamic changes in physical obstructions (such as closing), and updating of actual destinations. Second, the basic process of navigation seeking road

1. Basic steps

The following steps show you how to set up a navigation grid and how the agent can find a path on the navigation grid:

(1) Create some geometry in the level, such as planar (Plane) or terrain (terrain), and then click Static (Static) in the upper-right corner of the viewer window (Inspector), and for Unity 5.x, when the left side of the static becomes "√", Then click the drop-down box to the right of it to see that the following options for the geometry are selected by default:

You can also change it to only check navigation static (Navigation static):

In the above, the "Navigation" tab on the right side of the inspector is the navigation grid window that opens through window, Navigation mesh. In the tab window, you can set the bake parameters and click the Bake (Bake) button when the settings are complete, resulting in all navigation grids that navigate the "static" geometry.

(2) Create some "dynamic" geometry (such as a character) in the scene, and then create a proxy (or multiple proxies) for the geometry by adding the navmeshagent component to the dynamic geometry in the scene.

(3) In the script attached to the agent, provide a destination for the proxy so that you can specify the navigation target in the Unity Editor by setting the destination property for the script.

(4) When you click the Play button, you can watch the animated process of dynamic geometry automatically navigating the pathfinding.

Note that you can also customize the NavMesh layer. These layers may be required to make the agent easier to pass somewhere in the environment (relative to other places).

For a mesh part that is not directly connected, you can generate a detached mesh link (Off Mash link Generation), which links the discontinuous meshes one by one, further realizing the function of pathfinding.

2. Baking (Bake) and its properties

For objects marked as static (static), after opening the navigation Grid window with "window", "Navigation mesh", set the parameters to bake in the "Bake" tab of the Navigation view:

The following are the properties that affect the results of the navigation grid (Navmesh) Baking:

"Agent radius": The radius of the "typical" proxy (preferably the minimum value).

"Agent height": The height of the "typical" agent (the role passes the desired "gap").

Max Slope: Maximum slope. All surfaces with a slope greater than this value are discarded.

"Step height": Step heights. When the height difference of the adjacent mesh is lower than the height of the stair, it is considered to be connected to the navigation grid area.

"Drop height": drop altitude. If the property value is positive, the split grid link is placed for the adjacent navigation mesh surface with a height difference less than that value.

"Jump distance": jumping distance. If the property value is positive, a detached grid link is placed for the surface of the adjacent navigation grid that has a horizontal distance less than the value.

"Min Region area": Minimum area. Areas smaller than this threshold will be discarded.

"Height mesh": Height mesh. If this option is checked, the original height information is stored. This can have a certain effect on speed and memory performance.

Note that the baked navigation grid becomes part of the scene and the agent navigates through it. To delete the navigation grid, click the Clear button in the Bake (Bake) tab.

3. Explanation of Details

When you bake a navigation grid (Navmesh), it maps Navmesh to squares in the XZ plane. When you visualize a square, its border is treated as a bright blue axis snapline on the navigation grid (Navmesh). Unity supports up to 1024 squares in a scene, each of which is represented by 1000x100 pixels. If you intend to allow the agent to navigate large areas, you need to be aware of the size of the navigation grid (Navmesh) and the final number of meshes.

The default setting for agent radius is 0.5, and the default setting for width error (inaccuracy) is 0.16666667 (16.666667%). The default setting of the square edge length can be calculated as:

1000 * (Depth of RADIUS) * Width error = 1000 * (2*0.5) * 0.16666667 = 166.66667.

Increasing the width inaccuracy will allow larger areas to be accommodated, but doing so will reduce the precision of the navigation grid (Navmesh).

For example, if the grid has a total of x 32 squares, it will have 1024 squares. This means that if you have a really huge terrain that you want to use with the navigation grid (Navmesh), by default, the terrain area must not exceed 5.333 times 5.333 km (32 * 166.66667 meters).

"Unity" 12.1 Basic concepts

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.