navigation_using_navigationpathqueryobjects.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. .. _doc_navigation_using_navigationpathqueryobjects:
  2. Using NavigationPathQueryObjects
  3. ================================
  4. ``NavigationPathQueryObjects`` can be used together with ``NavigationServer.query_path()``
  5. to obtain a heavily **customized** navigation path including optional **meta data** about the path.
  6. This requires more setup compared to obtaining a normal NavigationPath but lets you tailor
  7. the pathfinding and provided path data to the different needs of a project.
  8. NavigationPathQueryObjects consist of a pair of objects, a ``NavigationPathQueryParameters`` object holding the customization options
  9. for the query and a ``NavigationPathQueryResult`` that receives (regular) updates with the resulting path and meta data from the query.
  10. 2D and 3D versions of ``NavigationPathQueryParameters`` are available as
  11. :ref:`NavigationPathQueryParameters2D<class_NavigationPathQueryParameters2D>` and
  12. :ref:`NavigationPathQueryParameters3D<class_NavigationPathQueryParameters3D>` respectively.
  13. 2D and 3D versions of ``NavigationPathQueryResult`` are available as
  14. :ref:`NavigationPathQuerResult2D<class_NavigationPathQueryResult2D>` and
  15. :ref:`NavigationPathQueryResult3D<class_NavigationPathQueryResult3D>` respectively.
  16. Both parameters and result are used as a pair with the ``NavigationServer.query_path()`` function.
  17. For the available customization options and their use see the class doc of the parameters.
  18. While not a strict requirement, both objects are intended to be created once in advance, stored in a
  19. persistent variable for the agent and reused for every followup path query with updated parameters.
  20. This reuse avoids performance implications from frequent object creation if a project
  21. has a large quantity of simultaneous agents that regularly update their paths.
  22. .. tabs::
  23. .. code-tab:: gdscript GDScript
  24. # prepare query objects
  25. var query_parameters = NavigationPathQueryParameters2D.new()
  26. var query_result = NavigationPathQueryResult2D.new()
  27. # update parameters object
  28. query_parameters.map = get_world_2d().get_navigation_map()
  29. query_parameters.start_position = agent2d_current_global_position
  30. query_parameters.target_position = agent2d_target_global_position
  31. # update result object
  32. NavigationServer2D.query_path(query_parameters, query_result)
  33. var path: PackedVector2Array = query_result.get_path()
  34. .. tabs::
  35. .. code-tab:: gdscript GDScript
  36. # prepare query objects
  37. var query_parameters = NavigationPathQueryParameters3D.new()
  38. var query_result = NavigationPathQueryResult3D.new()
  39. # update parameters object
  40. query_parameters.map = get_world_3d().get_navigation_map()
  41. query_parameters.start_position = agent3d_current_global_position
  42. query_parameters.target_position = agent3d_target_global_position
  43. # update result object
  44. NavigationServer3D.query_path(query_parameters, query_result)
  45. var path: PackedVector3Array = query_result.get_path()