navigation_using_navigationregions.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 navigationmesh 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 SceneTree add a ``NavigationRegion2D`` or ``NavigationRegion3D`` node to the scene.
  11. All regions require a navigationmesh resource to function. See :ref:`doc_navigation_using_navigationmeshes` to learn how to create and apply navigationmeshes.
  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 navmeshes of individual regions when they are close enough. For more detail 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 navigationmesh 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_region_rid()``.
  26. .. tabs::
  27. .. code-tab:: gdscript GDScript
  28. extends NavigationRegion3D
  29. var navigationserver_region_rid: RID = get_region_rid()
  30. New regions can also be created with the NavigationServer API and added to any existing map.
  31. If regions are created with the NavigationServer API directly they need to be assigned a navigation map manually.
  32. .. tabs::
  33. .. code-tab:: gdscript GDScript
  34. extends Node2D
  35. var new_2d_region_rid: RID = NavigationServer2D.region_create()
  36. var default_2d_map_rid: RID = get_world_2d().get_navigation_map()
  37. NavigationServer2D.region_set_map(new_2d_region_rid, default_2d_map_rid)
  38. .. tabs::
  39. .. code-tab:: gdscript GDScript
  40. extends Node3D
  41. var new_3d_region_rid: RID = NavigationServer3D.region_create()
  42. var default_3d_map_rid: RID = get_world_3d().get_navigation_map()
  43. NavigationServer3D.region_set_map(new_3d_region_rid, default_3d_map_rid)
  44. .. note::
  45. NavigationRegions can only be assigned to a single NavigationMap.
  46. If an existing region is assigned to a new map it will leave the old map.