navigation_using_navigationobstacles.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. .. _doc_navigation_using_navigationobstacles:
  2. Using NavigationObstacles
  3. =========================
  4. NavigationObstacles are used to set an avoidance radius around objects
  5. that, due to their constant movement, cannot be efficiently (re)baked
  6. to a 2D NavigationPolygon or 3D NavigationMesh.
  7. 2D and 3D versions of NavigationObstacles nodes are available as
  8. :ref:`NavigationObstacle2D<class_NavigationObstacle2D>` and
  9. :ref:`NavigationObstacle3D<class_NavigationObstacle3D>` respectively.
  10. NavigationObstacles are not intended for any kind of static geometry
  11. or temporary barriers that may change their position occasionally.
  12. Those changes should be (re)baked so actors can follow the outlines
  13. of these objects at higher detail with navigation paths. The obstacle avoidance
  14. should be seen as a last resort option intended for objects that are constantly moving.
  15. To use NavigationObstacles for avoidance, place a NavigationObstacle2D/3D node
  16. below a Node2D/3D inheriting parent node. While the obstacle node has an
  17. option to ``estimate_radius`` from child collisions, prefer to set a
  18. more reliable manual ``radius`` value. If estimated, the obstacle will use
  19. a radius that encapsulates the entire parent node which can result in a very large
  20. radius value if the parent is not a circle shape but e.g. a long rectangle shape.
  21. .. note::
  22. The obstacle ``radius`` is the area that will be strictly avoided whenever possible.
  23. Do not set it too large. Agents start to avoid way before
  24. this radius depending on parameters and velocity.
  25. While NavigationObstacle nodes do require a Node parent the NavigationServer obstacles do not.
  26. New obstacles created in scripts require only a ``map``, ``radius`` and ``position``.
  27. Obstacles can be placed directly on the NavigationMap with the NavigationServer API.
  28. .. tabs::
  29. .. code-tab:: gdscript GDScript
  30. extends Node3D
  31. # create a new "obstacle" agent and place it on the default map``
  32. var new_agent_rid: RID = NavigationServer3D.agent_create()
  33. var default_3d_map_rid: RID = get_world_3d().get_navigation_map()
  34. NavigationServer3D.agent_set_map(new_agent_rid, default_3d_map_rid)
  35. NavigationServer3D.agent_set_radius(new_agent_rid, 0.5)
  36. NavigationServer3D.agent_set_position(new_agent_rid, global_transform.origin)
  37. .. note::
  38. The NavigationServer API has no dedicated functions for obstacles.
  39. Obstacles are technically considered just normal agents.
  40. All "agent" prefixed functions are intended for obstacles as well.