navigation_using_navigationregions.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .. _doc_navigation_using_navigationregions:
  2. Using NavigationRegions
  3. =======================
  4. NavigationRegions are the visual Node representation of a **region** of the navigation **map** on the NavigationServer.
  5. Each NavigationRegion node holds a resource for the navigation mesh data.
  6. Both 2D and 3D version are available as :ref:`NavigationRegion2D<class_NavigationRegion2D>`
  7. and :ref:`NavigationRegion3D<class_NavigationRegion3D>` respectively.
  8. Individual NavigationRegions upload their 2D NavigationPolygon or 3D NavigationMesh resource data to the NavigationServer.
  9. The NavigationServer map turns this information into a combined navigation map for pathfinding.
  10. To create a navigation region using the scene tree add a ``NavigationRegion2D`` or ``NavigationRegion3D`` node to the scene.
  11. All regions require a navigation mesh resource to function. See :ref:`doc_navigation_using_navigationmeshes` to learn how to create and apply navigation meshes.
  12. NavigationRegions will automatically push ``global_transform`` changes to the region on the NavigationServer which makes them suitable for moving platforms.
  13. The NavigationServer will attempt to connect the navigation meshes of individual regions when they are close enough. For more details see :ref:`doc_navigation_connecting_navmesh`.
  14. To connect NavigationRegions over arbitrary distances see :ref:`doc_navigation_using_navigationlinks` to learn how to create and use ``NavigationLinks``.
  15. .. warning::
  16. While changing the transform of a NavigationRegion node does update the region position on the
  17. NavigationServer, changing the scale does not. A navigation mesh resource has no scale and needs
  18. to be fully updated when source geometry changes scale.
  19. Regions can be enabled / disabled and if disabled will not contribute to future pathfinding queries.
  20. .. note::
  21. Existing paths will not be automatically updated when a region gets enabled / disabled.
  22. Creating new navigation regions
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. New NavigationRegion nodes will automatically register to the default world navigation map for their 2D/3D dimension.
  25. The region RID can then be obtained from NavigationRegion Nodes with ``get_rid()``.
  26. .. tabs::
  27. .. code-tab:: gdscript 2D GDScript
  28. extends NavigationRegion2D
  29. var navigationserver_region_rid: RID = get_rid()
  30. .. code-tab:: gdscript 3D GDScript
  31. extends NavigationRegion3D
  32. var navigationserver_region_rid: RID = get_rid()
  33. New regions can also be created with the NavigationServer API and added to any existing map.
  34. If regions are created with the NavigationServer API directly they need to be assigned a navigation map manually.
  35. .. tabs::
  36. .. code-tab:: gdscript 2D GDScript
  37. extends Node2D
  38. func _ready() -> void:
  39. var new_region_rid: RID = NavigationServer2D.region_create()
  40. var default_map_rid: RID = get_world_2d().get_navigation_map()
  41. NavigationServer2D.region_set_map(new_region_rid, default_map_rid)
  42. .. code-tab:: gdscript 3D GDScript
  43. extends Node3D
  44. func _ready() -> void:
  45. var new_region_rid: RID = NavigationServer3D.region_create()
  46. var default_map_rid: RID = get_world_3d().get_navigation_map()
  47. NavigationServer3D.region_set_map(new_region_rid, default_map_rid)
  48. .. note::
  49. Navigation regions can only be assigned to a single navigation map.
  50. If an existing region is assigned to a new navigation map it will leave the old map.