navigation_using_navigationmaps.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .. _doc_navigation_using_navigationmaps:
  2. Using NavigationMaps
  3. ====================
  4. .. image:: img/nav_maps.png
  5. A NavigationMap is an abstract navigation world on the NavigationServer identified by a NavigationServer :ref:`RID<class_RID>`.
  6. A map can hold and connect a near infinite number of navigation regions with navigation meshes to build the traversable areas of a game world for pathfinding.
  7. A map can contain avoidance agents. Collision avoidance will be calculated based on the agents present in the map.
  8. .. note::
  9. Different NavigationMaps are completely isolated from each other but navigation regions
  10. and avoidance agents can switch between different maps. Switches will become effective on NavigationServer synchronization.
  11. Default navigation maps
  12. ~~~~~~~~~~~~~~~~~~~~~~~
  13. By default Godot creates a navigation map for each :ref:`World2D<class_World2D>` and :ref:`World3D<class_World3D>` of the root viewport.
  14. The 2D default navigation map RID can be obtained with ``get_world_2d().get_navigation_map()`` from any :ref:`Node2D<class_Node2D>` inheriting Node.
  15. The 3D default navigation map RID can be obtained with ``get_world_3d().get_navigation_map()`` from any :ref:`Node3D<class_Node3D>` inheriting Node.
  16. .. tabs::
  17. .. code-tab:: gdscript 2D GDScript
  18. extends Node2D
  19. func _ready() -> void:
  20. var default_navigation_map_rid: RID = get_world_2d().get_navigation_map()
  21. .. code-tab:: csharp 2D C#
  22. public partial class MyNode2D : Node2D
  23. {
  24. public override void _Ready()
  25. {
  26. Rid defaultNavigationMapRid = GetWorld2D().NavigationMap;
  27. }
  28. }
  29. .. code-tab:: gdscript 3D GDScript
  30. extends Node3D
  31. func _ready() -> void:
  32. var default_navigation_map_rid: RID = get_world_3d().get_navigation_map()
  33. .. code-tab:: csharp 3D C#
  34. public partial class MyNode3D : Node3D
  35. {
  36. public override void _Ready()
  37. {
  38. Rid defaultNavigationMapRid = GetWorld3D().NavigationMap;
  39. }
  40. }
  41. Creating new navigation maps
  42. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. The NavigationServer can create and support as many navigation maps as required for specific gameplay.
  44. Additional navigation maps are created and handled by using the NavigationServer API
  45. directly e.g. to support different avoidance agent or actor locomotion types.
  46. For example uses of different navigation maps see :ref:`doc_navigation_different_actor_types` and :ref:`doc_navigation_different_actor_locomotion`.
  47. Each navigation map individually synchronizes queued changes to its navigation regions and avoidance agents.
  48. A navigation map that has not received changes will consume little to no processing time.
  49. Navigation regions and avoidance agents can only be part of a single navigation map but they can switch map at any time.
  50. .. note::
  51. A navigation map switch will take effect only after the next NavigationServer synchronization.
  52. .. tabs::
  53. .. code-tab:: gdscript 2D GDScript
  54. extends Node2D
  55. func _ready() -> void:
  56. var new_navigation_map: RID = NavigationServer2D.map_create()
  57. NavigationServer2D.map_set_active(new_navigation_map, true)
  58. .. code-tab:: csharp 2D C#
  59. public partial class MyNode2D : Node2D
  60. {
  61. public override void _Ready()
  62. {
  63. Rid newNavigationMap = NavigationServer2D.MapCreate();
  64. NavigationServer2D.MapSetActive(newNavigationMap, true);
  65. }
  66. }
  67. .. code-tab:: gdscript 3D GDScript
  68. extends Node3D
  69. func _ready() -> void:
  70. var new_navigation_map: RID = NavigationServer3D.map_create()
  71. NavigationServer3D.map_set_active(new_navigation_map, true)
  72. .. code-tab:: csharp 3D C#
  73. public partial class MyNode3D : Node3D
  74. {
  75. public override void _Ready()
  76. {
  77. Rid newNavigationMap = NavigationServer3D.MapCreate();
  78. NavigationServer3D.MapSetActive(newNavigationMap, true);
  79. }
  80. }
  81. .. note::
  82. There is no difference between navigation maps created with the NavigationServer2D API or the NavigationServer3D API.