Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

顯示導覽

../../_images/nav_maps.png

NavigationMap 即導覽地圖。NavigationMap 是抽象的導覽世界,位於 NavigationServer 中,使用 NavigationServer 的 RID 標識。

地圖可以容納並連接近乎無限數量的導覽區域與導覽網格,以建立遊戲世界的可走訪區域以進行尋路。

A map can contain avoidance agents. Collision avoidance will be calculated based on the agents present in the map.

備註

Different NavigationMaps are completely isolated from each other but navigation regions and avoidance agents can switch between different maps. Switches will become effective on NavigationServer synchronization.

建立導覽 (-navmesh)

By default Godot creates a navigation map for each World2D and World3D of the root viewport.

The 2D default navigation map RID can be obtained with get_world_2d().get_navigation_map() from any Node2D inheriting Node.

The 3D default navigation map RID can be obtained with get_world_3d().get_navigation_map() from any Node3D inheriting Node.

extends Node2D

var default_2d_navigation_map_rid: RID = get_world_2d().get_navigation_map()
extends Node3D

var default_3d_navigation_map_rid: RID = get_world_3d().get_navigation_map()

建立導覽 (-navmesh)

The NavigationServer can create and support as many navigation maps as required for specific gameplay. Additional navigation maps are created and handled by using the NavigationServer API directly e.g. to support different avoidance agent or actor locomotion types.

有關不同導覽地圖的使用範例,請參閱 doc_navigation_ Different_actor_types 和 doc_navigation_ different_actor_locomotion 。

Each navigation map individually synchronizes queued changes to its navigation regions and avoidance agents. A navigation map that has not received changes will consume little to no processing time. Navigation regions and avoidance agents can only be part of a single navigation map but they can switch map at any time.

備註

導覽地圖切換只有在下次NavigationServer同步後才會生效。

extends Node2D

var new_navigation_map: RID = NavigationServer2D.map_create()
NavigationServer2D.map_set_active(true)
extends Node3D

var new_navigation_map: RID = NavigationServer3D.map_create()
NavigationServer3D.map_set_active(true)

備註

使用 NavigationServer2D API 或 NavigationServer3D API 建立的導覽地圖沒有差異。