real_time_navigation_3d.rst 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .. _doc_real_time_navigation_3d:
  2. Real Time Navigation (3D)
  3. =========================
  4. Introduction
  5. ------------
  6. Godot provides two nodes which can be used to achieve real time navigation
  7. in a 3D environment, :ref:`Navigation <class_Navigation>` and :ref:`NavigationMeshInstance <class_NavigationMeshInstance>`.
  8. A navigation mesh instance is used to hold a :ref:`NavigationMesh <class_NavigationMesh>`,
  9. which defines what areas in a scene can be navigated to. The :ref:`Navigation <class_Navigation>`
  10. node is then used for pathfinding with the navigation mesh.
  11. Setting up navigation
  12. ---------------------
  13. To add navigation to a scene you need to add a navigation node, then
  14. a navigation mesh instance as a child of the navigation node. With the
  15. navigation mesh instance selected you need to go to the inspector and
  16. create a new navigation mesh.
  17. .. image:: img/new_navigation_mesh.png
  18. Click on the navigation mesh and you can now alter the properties that
  19. define how the navigation mesh is generated. You can find a full
  20. description for each of the properties in the class reference here:
  21. :ref:`NavigationMesh <class_NavigationMesh>`.
  22. After making the changes you want the mesh can be generated by clicking
  23. **Bake NavMesh** in the toolbar.
  24. .. image:: img/bake_navmesh.png
  25. Once the mesh has finished generating you should see the transparent
  26. navigation mesh above the areas in your scene that can be navigated to.
  27. .. image:: img/baked_navmesh.png
  28. Keep in mind that the navmesh shows where the center of an entity can
  29. go. For example, if you set the agent radius to 0.5 then your
  30. navigation mesh will have a distance of 0.5 from any ledges or walls
  31. to prevent clipping into the wall or hanging off of the edge.
  32. Generating a path
  33. -----------------
  34. To get a path between two areas on a map you use the navigation node
  35. method ``get_simple_path()``. The first argument is a Vector3 of the
  36. starting location, the next is a Vector3 of the end location. And the
  37. last argument is a boolean for whether or not agent properties of a
  38. navmesh are considered when generating a path.
  39. The method will return a :ref:`PoolVector3Array <class_PoolVector3Array>` consisting of
  40. points that make a path. If there is no way to navigate to the end
  41. location the method will return a blank :ref:`PoolVector3Array <class_PoolVector3Array>`.
  42. Official example project
  43. ------------------------
  44. There is an official example project on how to use 3D navigation.
  45. You can find the repository `here <https://github.com/godotengine/godot-demo-projects/tree/master/3d/navmesh>`__.
  46. It can also be found in the asset library.