navigation_connecting_navmesh.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. .. _doc_navigation_connecting_navmesh:
  2. Connecting navigation meshes
  3. ============================
  4. Different NavigationMeshes are automatically merged by the NavigationServer
  5. when at least two vertex positions of one edge exactly overlap.
  6. To connect over arbitrary distances see :ref:`doc_navigation_using_navigationlinks`.
  7. .. image:: img/navigation_vertex_merge.png
  8. The same is true for multiple NavigationPolygon resources. As long as their
  9. outline points overlap exactly the NavigationServer will merge them.
  10. NavigationPolygon outlines must be from different NavigationPolygon resources to connect.
  11. Overlapping or intersecting outlines on the same NavigationPolygon
  12. will fail the navigation mesh creation. Overlapping or intersecting
  13. outlines from different NavigationPolygons will often fail to create the
  14. navigation region edge connections on the NavigationServer and should be avoided.
  15. .. image:: img/navigation_vertex_merge2.png
  16. .. warning::
  17. Exactly means exactly for the vertex position merge. Small float errors
  18. that happen quite regularly with imported meshes will prevent a successful vertex merge.
  19. Alternatively navigation meshes are not merged but still considered as **connected** by
  20. the NavigationServer when their edges are nearly parallel and within distance
  21. to each other. The connection distance is defined by the ``edge_connection_margin`` for each
  22. navigation map. In many cases navigation mesh edges cannot properly connect when they partly overlap.
  23. Better avoid any navigation mesh overlap at all time for a consistent merge behavior.
  24. .. image:: img/navigation_edge_connection.png
  25. If navigation debug is enabled and the NavigationServer active the established navigation mesh connections will be visualized.
  26. See :ref:`doc_navigation_debug_tools` for more info about navigation debug options.
  27. The default 2D ``edge_connection_margin`` can be changed in the ProjectSettings under ``navigation/2d/default_edge_connection_margin``.
  28. The default 3D ``edge_connection_margin`` can be changed in the ProjectSettings under ``navigation/3d/default_edge_connection_margin``.
  29. The edge connection margin value of any navigation map can also be changed at runtime with the NavigationServer API.
  30. .. tabs::
  31. .. code-tab:: gdscript 2D GDScript
  32. extends Node2D
  33. func _ready() -> void:
  34. # 2D margins are designed to work with 2D "pixel" values.
  35. var default_map_rid: RID = get_world_2d().get_navigation_map()
  36. NavigationServer2D.map_set_edge_connection_margin(default_map_rid, 50.0)
  37. .. code-tab:: csharp 2D C#
  38. using Godot;
  39. public partial class MyNode2D : Node2D
  40. {
  41. public override void _Ready()
  42. {
  43. // 2D margins are designed to work with 2D "pixel" values.
  44. Rid defaultMapRid = GetWorld2D().NavigationMap;
  45. NavigationServer2D.MapSetEdgeConnectionMargin(defaultMapRid, 50.0f);
  46. }
  47. }
  48. .. code-tab:: gdscript 3D GDScript
  49. extends Node3D
  50. func _ready() -> void:
  51. # 3D margins are designed to work with 3D world unit values.
  52. var default_map_rid: RID = get_world_3d().get_navigation_map()
  53. NavigationServer3D.map_set_edge_connection_margin(default_map_rid, 0.5)
  54. .. code-tab:: csharp 3D C#
  55. using Godot;
  56. public partial class MyNode3D : Node3D
  57. {
  58. public override void _Ready()
  59. {
  60. // 3D margins are designed to work with 3D world unit values.
  61. Rid defaultMapRid = GetWorld3D().NavigationMap;
  62. NavigationServer3D.MapSetEdgeConnectionMargin(defaultMapRid, 0.5f);
  63. }
  64. }
  65. .. note::
  66. Changing the edge connection margin will trigger a full update of all navigation mesh connections on the NavigationServer.