使用 NavigationRegion

NavigationRegion 即导航区块,是对 NavigationServer 的导航地图中某个区块的可视化 Node 表示。每个 NavigationRegion 节点中都存放着导航网格数据资源。

2D 和 3D 版本分别为 NavigationRegion2DNavigationRegion3D

Individual NavigationRegions upload their 2D NavigationPolygon or 3D NavigationMesh resource data to the NavigationServer. The NavigationServer map turns this information into a combined navigation map for pathfinding.

To create a navigation region using the scene tree add a NavigationRegion2D or NavigationRegion3D node to the scene. All regions require a navigation mesh resource to function. See 使用导航网格 to learn how to create and apply navigation meshes.

NavigationRegions will automatically push global_transform changes to the region on the NavigationServer which makes them suitable for moving platforms. The NavigationServer will attempt to connect the navigation meshes of individual regions when they are close enough. For more details see 连接导航网格. To connect NavigationRegions over arbitrary distances see 使用 NavigationLink to learn how to create and use NavigationLinks.

警告

While changing the transform of a NavigationRegion node does update the region position on the NavigationServer, changing the scale does not. A navigation mesh resource has no scale and needs to be fully updated when source geometry changes scale.

Regions can be enabled / disabled and if disabled will not contribute to future pathfinding queries.

备注

Existing paths will not be automatically updated when a region gets enabled / disabled.

新建导航区块

New NavigationRegion nodes will automatically register to the default world navigation map for their 2D/3D dimension.

The region RID can then be obtained from NavigationRegion Nodes with get_region_rid().

GDScript

  1. extends NavigationRegion3D
  2. var navigationserver_region_rid: RID = get_region_rid()

New regions can also be created with the NavigationServer API and added to any existing map.

If regions are created with the NavigationServer API directly they need to be assigned a navigation map manually.

GDScript

  1. extends Node2D
  2. var new_2d_region_rid: RID = NavigationServer2D.region_create()
  3. var default_2d_map_rid: RID = get_world_2d().get_navigation_map()
  4. NavigationServer2D.region_set_map(new_2d_region_rid, default_2d_map_rid)

GDScript

  1. extends Node3D
  2. var new_3d_region_rid: RID = NavigationServer3D.region_create()
  3. var default_3d_map_rid: RID = get_world_3d().get_navigation_map()
  4. NavigationServer3D.region_set_map(new_3d_region_rid, default_3d_map_rid)

备注

NavigationRegions can only be assigned to a single NavigationMap. If an existing region is assigned to a new map it will leave the old map.

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.