navigation_using_navigationmaps.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 be joined by avoidance agents to process collision avoidance between the avoidance agents.
  8. .. note::
  9. Different NavigationMaps are completely isolated from each other but navigation regions
  10. and avoidance agents can switch between different maps once every server synchronization.
  11. Default navigation maps
  12. ~~~~~~~~~~~~~~~~~~~~~~~
  13. By default Godot creates a navigation map RID for each :ref:`World2D<class_World2D>` and :ref:`World3D<class_World3D>` of the root viewport.
  14. The 2D default navigation ``map`` can be obtained with ``get_world_2d().get_navigation_map()`` from any :ref:`Node2D<class_Node2D>` inheriting Node.
  15. The 3D default navigation ``map`` can be obtained with ``get_world_3d().get_navigation_map()`` from any :ref:`Node3D<class_Node3D>` inheriting Node.
  16. .. tabs::
  17. .. code-tab:: gdscript GDScript
  18. extends Node2D
  19. var default_2d_navigation_map_rid: RID = get_world_2d().get_navigation_map()
  20. .. tabs::
  21. .. code-tab:: gdscript GDScript
  22. extends Node3D
  23. var default_3d_navigation_map_rid: RID = get_world_3d().get_navigation_map()
  24. Creating new navigation maps
  25. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. The NavigationServer can create and support as many navigation maps as are required for specific gameplay.
  27. Additional navigation maps are created and maintained by using the NavigationServer API
  28. directly e.g. to support different avoidance agent or actor locomotion types.
  29. For example uses of different navigation maps see :ref:`doc_navigation_different_actor_types` and :ref:`doc_navigation_different_actor_locomotion`.
  30. Each navigation map synchronizes queued changes to its navigation regions and avoidance agents individually.
  31. A navigation map that has not received changes will consume little to no processing time.
  32. Navigation regions and avoidance agents can only be part of a single navigations map but they can switch maps at any time.
  33. .. note::
  34. A navigation map switch will take effect only after the next NavigationServer synchronization.
  35. .. tabs::
  36. .. code-tab:: gdscript GDScript
  37. extends Node2D
  38. var new_navigation_map: RID = NavigationServer2D.map_create()
  39. NavigationServer2D.map_set_active(true)
  40. .. tabs::
  41. .. code-tab:: gdscript GDScript
  42. extends Node3D
  43. var new_navigation_map: RID = NavigationServer3D.map_create()
  44. NavigationServer3D.map_set_active(true)
  45. .. note::
  46. There is no difference between navigation maps created with the NavigationServer2D API or the NavigationServer3D API.