navigation_agent.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*************************************************************************/
  2. /* navigation_agent.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef NAVIGATION_AGENT_H
  31. #define NAVIGATION_AGENT_H
  32. #include "core/vector.h"
  33. #include "scene/main/node.h"
  34. class Spatial;
  35. class Navigation;
  36. class NavigationAgent : public Node {
  37. GDCLASS(NavigationAgent, Node);
  38. Spatial *agent_parent;
  39. Navigation *navigation;
  40. RID agent;
  41. real_t target_desired_distance;
  42. real_t radius;
  43. real_t navigation_height_offset;
  44. bool ignore_y;
  45. real_t neighbor_dist;
  46. int max_neighbors;
  47. real_t time_horizon;
  48. real_t max_speed;
  49. real_t path_max_distance;
  50. Vector3 target_location;
  51. Vector<Vector3> navigation_path;
  52. int nav_path_index;
  53. bool velocity_submitted;
  54. Vector3 prev_safe_velocity;
  55. /// The submitted target velocity
  56. Vector3 target_velocity;
  57. bool target_reached;
  58. bool navigation_finished;
  59. // No initialized on purpose
  60. uint32_t update_frame_id;
  61. protected:
  62. static void _bind_methods();
  63. void _notification(int p_what);
  64. public:
  65. NavigationAgent();
  66. virtual ~NavigationAgent();
  67. void set_navigation(Navigation *p_nav);
  68. const Navigation *get_navigation() const {
  69. return navigation;
  70. }
  71. void set_navigation_node(Node *p_nav);
  72. Node *get_navigation_node() const;
  73. RID get_rid() const {
  74. return agent;
  75. }
  76. void set_target_desired_distance(real_t p_dd);
  77. real_t get_target_desired_distance() const {
  78. return target_desired_distance;
  79. }
  80. void set_radius(real_t p_radius);
  81. real_t get_radius() const {
  82. return radius;
  83. }
  84. void set_agent_height_offset(real_t p_hh);
  85. real_t get_agent_height_offset() const {
  86. return navigation_height_offset;
  87. }
  88. void set_ignore_y(bool p_ignore_y);
  89. bool get_ignore_y() const {
  90. return ignore_y;
  91. }
  92. void set_neighbor_dist(real_t p_dist);
  93. real_t get_neighbor_dist() const {
  94. return neighbor_dist;
  95. }
  96. void set_max_neighbors(int p_count);
  97. int get_max_neighbors() const {
  98. return max_neighbors;
  99. }
  100. void set_time_horizon(real_t p_time);
  101. real_t get_time_horizon() const {
  102. return time_horizon;
  103. }
  104. void set_max_speed(real_t p_max_speed);
  105. real_t get_max_speed() const {
  106. return max_speed;
  107. }
  108. void set_path_max_distance(real_t p_pmd);
  109. real_t get_path_max_distance();
  110. void set_target_location(Vector3 p_location);
  111. Vector3 get_target_location() const;
  112. Vector3 get_next_location();
  113. Vector<Vector3> get_nav_path() const {
  114. return navigation_path;
  115. }
  116. int get_nav_path_index() const {
  117. return nav_path_index;
  118. }
  119. real_t distance_to_target() const;
  120. bool is_target_reached() const;
  121. bool is_target_reachable();
  122. bool is_navigation_finished();
  123. Vector3 get_final_location();
  124. void set_velocity(Vector3 p_velocity);
  125. void _avoidance_done(Vector3 p_new_velocity);
  126. virtual String get_configuration_warning() const;
  127. private:
  128. void update_navigation();
  129. };
  130. #endif