real_time_navigation_3d.rst 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .. _doc_real_time_navigation_3d:
  2. Real Time Navigation (3D)
  3. =========================
  4. Introduction
  5. ------------
  6. Pathfinding in a 3D environment is crucial for many games, it's commonly
  7. how non directly controlled characters or entities find their way around
  8. an environment. Godot provides several nodes for this purpose:
  9. - :ref:`NavigationRegion3D<class_NavigationRegion3D>`
  10. - :ref:`NavigationAgent3D<class_NavigationAgent3D>`
  11. - :ref:`NavigationObstacle3D<class_NavigationObstacle3D>`
  12. The map and navigation regions
  13. ------------------------------
  14. The "map" is the entire world for navigation, it's similar to "space" for
  15. the physics engine. It's comprised of navigation regions, these regions
  16. define what parts of the world that can be navigated around by navigation
  17. agents.
  18. To create a navigation region add the `NavigationRegion3D<class_NavigationRegion3D>`
  19. node to a 3D scene. Next in the inspector for that region create or add a
  20. :ref:`NavigationMesh<class_NavigationMesh>`. The navmesh contains options
  21. for how it will be generated when it's baked. The geometry options control
  22. which nodes, and types of nodes, are used to bake the mesh. A full
  23. description of each setting and how it works can be found in the :ref:`NavigationMesh class reference<class_NavigationMesh>`.
  24. Once the settings have been properly configured press the "Bake NavMesh"
  25. button at the top of the inspector to generate it.
  26. .. image:: img/bake_navmesh.png
  27. .. note::
  28. It can also be generated at runtime using the `bake_navigation_region()`
  29. method of the navigation region node.
  30. Once the mesh has finished generating you should see the transparent
  31. navigation mesh above the areas in the scene that can be navigated to.
  32. .. image:: img/baked_navmesh.png
  33. Keep in mind that the navmesh shows where the center of an entity can
  34. go. For example, if you set the agent radius to 0.5 then the
  35. navigation mesh will have a distance of 0.5 from any ledges or walls
  36. to prevent clipping into the wall or hanging off of the edge.
  37. Navigation agents can moved from one region to another if they are next
  38. to each other. Additionally A baked navmesh can be moved at runtime and
  39. agents will still be able to navigate onto it from another region.
  40. For example, navigating onto a moving platform that has stopped will work.
  41. NavigationAgent3D
  42. -----------------
  43. Navigation agent nodes are what actually does the pathfinding in a scene,
  44. one can be attached to the root node of an entity that needs to navigate.
  45. To have it pathfind use its `set_target_location` method. Once the target
  46. has been set a path will be generated to the node using navigation regions,
  47. with several points on the way to the final destination.
  48. RVO processing
  49. --------------
  50. RVO stands for reciprocal velocity obstacle. RVO processing is a way to
  51. pathfind while taking into account other agents and physics bodies that
  52. are also moving.
  53. To use it set a target like normal. Then an agent needs to fetch its next
  54. nav path location, and compute its velocity to that location. Instead
  55. of using that value to move use it to set the velocity on the agent
  56. with `set_velocity`. Then a new velocity that takes into account other
  57. agents and obstacles is generated and emitted with the signal `velocity_computed`.
  58. However agents can only take into account a set number of other nearby
  59. agents, this is the :ref:`max neighbors<class_NavigationAgent3D_property_max_neighbors>`
  60. property of an agent and can be adjusted. This is **not** a limit for
  61. how many agents can use a navigation region at the same time.
  62. NavigationObstacle3D
  63. --------------------
  64. This node is used to mark physics bodies that move around a navigation area
  65. that agents need to avoid (this will only work if you use RVO processing).
  66. For example, this node would be useful for pieces of debris in a destructible
  67. environment. Add it as the child of a physics body and navigation agent
  68. nodes will avoid it while pathfinding.