navigation_agent.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**************************************************************************/
  2. /* navigation_agent.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 = nullptr;
  39. Navigation *navigation = nullptr;
  40. RID agent;
  41. RID map_before_pause;
  42. RID map_override;
  43. bool avoidance_enabled = false;
  44. uint32_t navigation_layers = 1;
  45. real_t path_desired_distance = 1.0;
  46. real_t target_desired_distance = 1.0;
  47. real_t radius = 0.0;
  48. real_t navigation_height_offset = 0.0;
  49. bool ignore_y = false;
  50. real_t neighbor_dist = 0.0;
  51. int max_neighbors = 0;
  52. real_t time_horizon = 0.0;
  53. real_t max_speed = 0.0;
  54. real_t path_max_distance = 3.0;
  55. Vector3 target_location;
  56. Vector<Vector3> navigation_path;
  57. int nav_path_index = 0;
  58. bool velocity_submitted = false;
  59. Vector3 prev_safe_velocity;
  60. /// The submitted target velocity
  61. Vector3 target_velocity;
  62. bool target_reached = false;
  63. bool navigation_finished = true;
  64. // No initialized on purpose
  65. uint32_t update_frame_id = 0;
  66. protected:
  67. static void _bind_methods();
  68. void _notification(int p_what);
  69. public:
  70. NavigationAgent();
  71. virtual ~NavigationAgent();
  72. void set_navigation(Navigation *p_nav);
  73. const Navigation *get_navigation() const {
  74. return navigation;
  75. }
  76. void set_navigation_node(Node *p_nav);
  77. Node *get_navigation_node() const;
  78. RID get_rid() const {
  79. return agent;
  80. }
  81. void set_avoidance_enabled(bool p_enabled);
  82. bool get_avoidance_enabled() const;
  83. void set_agent_parent(Node *p_agent_parent);
  84. void set_navigation_layers(uint32_t p_navigation_layers);
  85. uint32_t get_navigation_layers() const;
  86. void set_navigation_map(RID p_navigation_map);
  87. RID get_navigation_map() const;
  88. void set_path_desired_distance(real_t p_dd);
  89. real_t get_path_desired_distance() const {
  90. return path_desired_distance;
  91. }
  92. void set_target_desired_distance(real_t p_dd);
  93. real_t get_target_desired_distance() const {
  94. return target_desired_distance;
  95. }
  96. void set_radius(real_t p_radius);
  97. real_t get_radius() const {
  98. return radius;
  99. }
  100. void set_agent_height_offset(real_t p_hh);
  101. real_t get_agent_height_offset() const {
  102. return navigation_height_offset;
  103. }
  104. void set_ignore_y(bool p_ignore_y);
  105. bool get_ignore_y() const {
  106. return ignore_y;
  107. }
  108. void set_neighbor_dist(real_t p_dist);
  109. real_t get_neighbor_dist() const {
  110. return neighbor_dist;
  111. }
  112. void set_max_neighbors(int p_count);
  113. int get_max_neighbors() const {
  114. return max_neighbors;
  115. }
  116. void set_time_horizon(real_t p_time);
  117. real_t get_time_horizon() const {
  118. return time_horizon;
  119. }
  120. void set_max_speed(real_t p_max_speed);
  121. real_t get_max_speed() const {
  122. return max_speed;
  123. }
  124. void set_path_max_distance(real_t p_pmd);
  125. real_t get_path_max_distance();
  126. void set_target_location(Vector3 p_location);
  127. Vector3 get_target_location() const;
  128. Vector3 get_next_location();
  129. Vector<Vector3> get_nav_path() const {
  130. return navigation_path;
  131. }
  132. int get_nav_path_index() const {
  133. return nav_path_index;
  134. }
  135. real_t distance_to_target() const;
  136. bool is_target_reached() const;
  137. bool is_target_reachable();
  138. bool is_navigation_finished();
  139. Vector3 get_final_location();
  140. void set_velocity(Vector3 p_velocity);
  141. void _avoidance_done(Vector3 p_new_velocity);
  142. virtual String get_configuration_warning() const;
  143. private:
  144. void update_navigation();
  145. void _request_repath();
  146. void _check_distance_to_target();
  147. };
  148. #endif // NAVIGATION_AGENT_H