|
@@ -48,11 +48,14 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent3D::set_radius);
|
|
|
ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent3D::get_radius);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("set_agent_height_offset", "agent_height_offset"), &NavigationAgent3D::set_agent_height_offset);
|
|
|
- ClassDB::bind_method(D_METHOD("get_agent_height_offset"), &NavigationAgent3D::get_agent_height_offset);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_height", "height"), &NavigationAgent3D::set_height);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_height"), &NavigationAgent3D::get_height);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("set_ignore_y", "ignore"), &NavigationAgent3D::set_ignore_y);
|
|
|
- ClassDB::bind_method(D_METHOD("get_ignore_y"), &NavigationAgent3D::get_ignore_y);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_path_height_offset", "path_height_offset"), &NavigationAgent3D::set_path_height_offset);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_path_height_offset"), &NavigationAgent3D::get_path_height_offset);
|
|
|
+
|
|
|
+ ClassDB::bind_method(D_METHOD("set_use_3d_avoidance", "enabled"), &NavigationAgent3D::set_use_3d_avoidance);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_use_3d_avoidance"), &NavigationAgent3D::get_use_3d_avoidance);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_neighbor_distance", "neighbor_distance"), &NavigationAgent3D::set_neighbor_distance);
|
|
|
ClassDB::bind_method(D_METHOD("get_neighbor_distance"), &NavigationAgent3D::get_neighbor_distance);
|
|
@@ -60,8 +63,11 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent3D::set_max_neighbors);
|
|
|
ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent3D::get_max_neighbors);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent3D::set_time_horizon);
|
|
|
- ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent3D::get_time_horizon);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_time_horizon_agents", "time_horizon"), &NavigationAgent3D::set_time_horizon_agents);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_time_horizon_agents"), &NavigationAgent3D::get_time_horizon_agents);
|
|
|
+
|
|
|
+ ClassDB::bind_method(D_METHOD("set_time_horizon_obstacles", "time_horizon"), &NavigationAgent3D::set_time_horizon_obstacles);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_time_horizon_obstacles"), &NavigationAgent3D::get_time_horizon_obstacles);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent3D::set_max_speed);
|
|
|
ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent3D::get_max_speed);
|
|
@@ -91,9 +97,16 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationAgent3D::get_target_position);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_next_path_position"), &NavigationAgent3D::get_next_path_position);
|
|
|
- ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent3D::distance_to_target);
|
|
|
+
|
|
|
+ ClassDB::bind_method(D_METHOD("set_velocity_forced", "velocity"), &NavigationAgent3D::set_velocity_forced);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent3D::set_velocity);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_velocity"), &NavigationAgent3D::get_velocity);
|
|
|
+
|
|
|
+ ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent3D::distance_to_target);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("get_current_navigation_result"), &NavigationAgent3D::get_current_navigation_result);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("get_current_navigation_path"), &NavigationAgent3D::get_current_navigation_path);
|
|
|
ClassDB::bind_method(D_METHOD("get_current_navigation_path_index"), &NavigationAgent3D::get_current_navigation_path_index);
|
|
|
ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent3D::is_target_reached);
|
|
@@ -103,11 +116,22 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent3D::_avoidance_done);
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("set_avoidance_layers", "layers"), &NavigationAgent3D::set_avoidance_layers);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_avoidance_layers"), &NavigationAgent3D::get_avoidance_layers);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_avoidance_mask", "mask"), &NavigationAgent3D::set_avoidance_mask);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_avoidance_mask"), &NavigationAgent3D::get_avoidance_mask);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_avoidance_layer_value", "layer_number", "value"), &NavigationAgent3D::set_avoidance_layer_value);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_avoidance_layer_value", "layer_number"), &NavigationAgent3D::get_avoidance_layer_value);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_avoidance_mask_value", "mask_number", "value"), &NavigationAgent3D::set_avoidance_mask_value);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_avoidance_mask_value", "mask_number"), &NavigationAgent3D::get_avoidance_mask_value);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_avoidance_priority", "priority"), &NavigationAgent3D::set_avoidance_priority);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_avoidance_priority"), &NavigationAgent3D::get_avoidance_priority);
|
|
|
+
|
|
|
ADD_GROUP("Pathfinding", "");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_target_position", "get_target_position");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,or_greater,suffix:m"), "set_path_desired_distance", "get_path_desired_distance");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,or_greater,suffix:m"), "set_target_desired_distance", "get_target_desired_distance");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_height_offset", PROPERTY_HINT_RANGE, "-100.0,100,0.01,or_greater,suffix:m"), "set_agent_height_offset", "get_agent_height_offset");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_height_offset", PROPERTY_HINT_RANGE, "-100.0,100,0.01,or_greater,suffix:m"), "set_path_height_offset", "get_path_height_offset");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_max_distance", PROPERTY_HINT_RANGE, "0.01,100,0.1,or_greater,suffix:m"), "set_path_max_distance", "get_path_max_distance");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm");
|
|
@@ -116,12 +140,18 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
|
|
|
ADD_GROUP("Avoidance", "");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.1,100,0.01,or_greater,suffix:m"), "set_radius", "get_radius");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_velocity", "get_velocity");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.01,100,0.01,or_greater,suffix:m"), "set_height", "get_height");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.01,100,0.01,or_greater,suffix:m"), "set_radius", "get_radius");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "neighbor_distance", PROPERTY_HINT_RANGE, "0.1,10000,0.01,or_greater,suffix:m"), "set_neighbor_distance", "get_neighbor_distance");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_neighbors", PROPERTY_HINT_RANGE, "1,10000,1,or_greater"), "set_max_neighbors", "get_max_neighbors");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_horizon", PROPERTY_HINT_RANGE, "0.01,10,0.01,or_greater,suffix:s"), "set_time_horizon", "get_time_horizon");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_speed", PROPERTY_HINT_RANGE, "0.1,1000,0.01,or_greater,suffix:m/s"), "set_max_speed", "get_max_speed");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_y"), "set_ignore_y", "get_ignore_y");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_horizon_agents", PROPERTY_HINT_RANGE, "0.0,10,0.01,or_greater,suffix:s"), "set_time_horizon_agents", "get_time_horizon_agents");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_horizon_obstacles", PROPERTY_HINT_RANGE, "0.0,10,0.01,or_greater,suffix:s"), "set_time_horizon_obstacles", "get_time_horizon_obstacles");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_speed", PROPERTY_HINT_RANGE, "0.01,10000,0.01,or_greater,suffix:m/s"), "set_max_speed", "get_max_speed");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_3d_avoidance"), "set_use_3d_avoidance", "get_use_3d_avoidance");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "avoidance_layers", PROPERTY_HINT_LAYERS_AVOIDANCE), "set_avoidance_layers", "get_avoidance_layers");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "avoidance_mask", PROPERTY_HINT_LAYERS_AVOIDANCE), "set_avoidance_mask", "get_avoidance_mask");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "avoidance_priority", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_avoidance_priority", "get_avoidance_priority");
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("path_changed"));
|
|
|
ADD_SIGNAL(MethodInfo("target_reached"));
|
|
@@ -146,6 +176,42 @@ void NavigationAgent3D::_bind_methods() {
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "debug_path_custom_point_size", PROPERTY_HINT_RANGE, "0,50,0.01,or_greater,suffix:px"), "set_debug_path_custom_point_size", "get_debug_path_custom_point_size");
|
|
|
}
|
|
|
|
|
|
+#ifndef DISABLE_DEPRECATED
|
|
|
+// Compatibility with Godot 4.0 beta 10 or below.
|
|
|
+// Functions in block below all renamed or replaced in 4.0 beta 1X avoidance rework.
|
|
|
+bool NavigationAgent3D::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
+ if (p_name == "time_horizon") {
|
|
|
+ set_time_horizon_agents(p_value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (p_name == "target_location") {
|
|
|
+ set_target_position(p_value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (p_name == "agent_height_offset") {
|
|
|
+ set_path_height_offset(p_value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool NavigationAgent3D::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
+ if (p_name == "time_horizon") {
|
|
|
+ r_ret = get_time_horizon_agents();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (p_name == "target_location") {
|
|
|
+ r_ret = get_target_position();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (p_name == "agent_height_offset") {
|
|
|
+ r_ret = get_path_height_offset();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+#endif // DISABLE_DEPRECATED
|
|
|
+
|
|
|
void NavigationAgent3D::_notification(int p_what) {
|
|
|
switch (p_what) {
|
|
|
case NOTIFICATION_POST_ENTER_TREE: {
|
|
@@ -154,11 +220,16 @@ void NavigationAgent3D::_notification(int p_what) {
|
|
|
set_agent_parent(get_parent());
|
|
|
set_physics_process_internal(true);
|
|
|
|
|
|
+ if (avoidance_enabled) {
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin);
|
|
|
+ }
|
|
|
+
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
if (NavigationServer3D::get_singleton()->get_debug_enabled()) {
|
|
|
debug_path_dirty = true;
|
|
|
}
|
|
|
#endif // DEBUG_ENABLED
|
|
|
+
|
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_PARENTED: {
|
|
@@ -211,10 +282,22 @@ void NavigationAgent3D::_notification(int p_what) {
|
|
|
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
|
|
if (agent_parent && target_position_submitted) {
|
|
|
- if (avoidance_enabled) {
|
|
|
- // agent_position on NavigationServer is avoidance only and has nothing to do with pathfinding
|
|
|
- // no point in flooding NavigationServer queue with agent position updates that get send to the void if avoidance is not used
|
|
|
- NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
|
|
|
+ if (velocity_submitted) {
|
|
|
+ velocity_submitted = false;
|
|
|
+ if (avoidance_enabled) {
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin);
|
|
|
+ if (!use_3d_avoidance) {
|
|
|
+ stored_y_velocity = velocity.y;
|
|
|
+ velocity.y = 0.0;
|
|
|
+ }
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_velocity(agent, velocity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (velocity_forced_submitted) {
|
|
|
+ velocity_forced_submitted = false;
|
|
|
+ if (avoidance_enabled) {
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_velocity_forced(agent, velocity_forced);
|
|
|
+ }
|
|
|
}
|
|
|
_check_distance_to_target();
|
|
|
}
|
|
@@ -229,12 +312,14 @@ void NavigationAgent3D::_notification(int p_what) {
|
|
|
|
|
|
NavigationAgent3D::NavigationAgent3D() {
|
|
|
agent = NavigationServer3D::get_singleton()->agent_create();
|
|
|
+
|
|
|
NavigationServer3D::get_singleton()->agent_set_neighbor_distance(agent, neighbor_distance);
|
|
|
NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors);
|
|
|
- NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, time_horizon);
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_time_horizon_agents(agent, time_horizon_agents);
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_time_horizon_obstacles(agent, time_horizon_obstacles);
|
|
|
NavigationServer3D::get_singleton()->agent_set_radius(agent, radius);
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_height(agent, height);
|
|
|
NavigationServer3D::get_singleton()->agent_set_max_speed(agent, max_speed);
|
|
|
- NavigationServer3D::get_singleton()->agent_set_ignore_y(agent, ignore_y);
|
|
|
|
|
|
// Preallocate query and result objects to improve performance.
|
|
|
navigation_query = Ref<NavigationPathQueryParameters3D>();
|
|
@@ -243,6 +328,12 @@ NavigationAgent3D::NavigationAgent3D() {
|
|
|
navigation_result = Ref<NavigationPathQueryResult3D>();
|
|
|
navigation_result.instantiate();
|
|
|
|
|
|
+ set_avoidance_layers(avoidance_layers);
|
|
|
+ set_avoidance_mask(avoidance_mask);
|
|
|
+ set_avoidance_priority(avoidance_priority);
|
|
|
+ set_use_3d_avoidance(use_3d_avoidance);
|
|
|
+ set_avoidance_enabled(avoidance_enabled);
|
|
|
+
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
NavigationServer3D::get_singleton()->connect(SNAME("navigation_debug_changed"), callable_mp(this, &NavigationAgent3D::_navigation_debug_changed));
|
|
|
#endif // DEBUG_ENABLED
|
|
@@ -274,9 +365,11 @@ void NavigationAgent3D::set_avoidance_enabled(bool p_enabled) {
|
|
|
avoidance_enabled = p_enabled;
|
|
|
|
|
|
if (avoidance_enabled) {
|
|
|
- NavigationServer3D::get_singleton()->agent_set_callback(agent, callable_mp(this, &NavigationAgent3D::_avoidance_done));
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_enabled(agent, true);
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_callback(agent, callable_mp(this, &NavigationAgent3D::_avoidance_done));
|
|
|
} else {
|
|
|
- NavigationServer3D::get_singleton()->agent_set_callback(agent, Callable());
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_enabled(agent, false);
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_callback(agent, Callable());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -290,7 +383,7 @@ void NavigationAgent3D::set_agent_parent(Node *p_agent_parent) {
|
|
|
}
|
|
|
|
|
|
// remove agent from any avoidance map before changing parent or there will be leftovers on the RVO map
|
|
|
- NavigationServer3D::get_singleton()->agent_set_callback(agent, Callable());
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_callback(agent, Callable());
|
|
|
|
|
|
if (Object::cast_to<Node3D>(p_agent_parent) != nullptr) {
|
|
|
// place agent on navigation map first or else the RVO agent callback creation fails silently later
|
|
@@ -303,7 +396,7 @@ void NavigationAgent3D::set_agent_parent(Node *p_agent_parent) {
|
|
|
|
|
|
// create new avoidance callback if enabled
|
|
|
if (avoidance_enabled) {
|
|
|
- NavigationServer3D::get_singleton()->agent_set_callback(agent, callable_mp(this, &NavigationAgent3D::_avoidance_done));
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_callback(agent, callable_mp(this, &NavigationAgent3D::_avoidance_done));
|
|
|
}
|
|
|
} else {
|
|
|
agent_parent = nullptr;
|
|
@@ -408,31 +501,32 @@ void NavigationAgent3D::set_target_desired_distance(real_t p_target_desired_dist
|
|
|
}
|
|
|
|
|
|
void NavigationAgent3D::set_radius(real_t p_radius) {
|
|
|
+ ERR_FAIL_COND_MSG(p_radius < 0.0, "Radius must be positive.");
|
|
|
if (Math::is_equal_approx(radius, p_radius)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
radius = p_radius;
|
|
|
|
|
|
NavigationServer3D::get_singleton()->agent_set_radius(agent, radius);
|
|
|
}
|
|
|
|
|
|
-void NavigationAgent3D::set_agent_height_offset(real_t p_agent_height_offset) {
|
|
|
- if (Math::is_equal_approx(navigation_height_offset, p_agent_height_offset)) {
|
|
|
+void NavigationAgent3D::set_height(real_t p_height) {
|
|
|
+ ERR_FAIL_COND_MSG(p_height < 0.0, "Height must be positive.");
|
|
|
+ if (Math::is_equal_approx(height, p_height)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- navigation_height_offset = p_agent_height_offset;
|
|
|
+ height = p_height;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_height(agent, height);
|
|
|
}
|
|
|
|
|
|
-void NavigationAgent3D::set_ignore_y(bool p_ignore_y) {
|
|
|
- if (ignore_y == p_ignore_y) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- ignore_y = p_ignore_y;
|
|
|
+void NavigationAgent3D::set_path_height_offset(real_t p_path_height_offset) {
|
|
|
+ path_height_offset = p_path_height_offset;
|
|
|
+}
|
|
|
|
|
|
- NavigationServer3D::get_singleton()->agent_set_ignore_y(agent, ignore_y);
|
|
|
+void NavigationAgent3D::set_use_3d_avoidance(bool p_use_3d_avoidance) {
|
|
|
+ use_3d_avoidance = p_use_3d_avoidance;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_use_3d_avoidance(agent, use_3d_avoidance);
|
|
|
+ notify_property_list_changed();
|
|
|
}
|
|
|
|
|
|
void NavigationAgent3D::set_neighbor_distance(real_t p_distance) {
|
|
@@ -455,21 +549,29 @@ void NavigationAgent3D::set_max_neighbors(int p_count) {
|
|
|
NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors);
|
|
|
}
|
|
|
|
|
|
-void NavigationAgent3D::set_time_horizon(real_t p_time) {
|
|
|
- if (Math::is_equal_approx(time_horizon, p_time)) {
|
|
|
+void NavigationAgent3D::set_time_horizon_agents(real_t p_time_horizon) {
|
|
|
+ ERR_FAIL_COND_MSG(p_time_horizon < 0.0, "Time horizion must be positive.");
|
|
|
+ if (Math::is_equal_approx(time_horizon_agents, p_time_horizon)) {
|
|
|
return;
|
|
|
}
|
|
|
+ time_horizon_agents = p_time_horizon;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_time_horizon_agents(agent, time_horizon_agents);
|
|
|
+}
|
|
|
|
|
|
- time_horizon = p_time;
|
|
|
-
|
|
|
- NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, time_horizon);
|
|
|
+void NavigationAgent3D::set_time_horizon_obstacles(real_t p_time_horizon) {
|
|
|
+ ERR_FAIL_COND_MSG(p_time_horizon < 0.0, "Time horizion must be positive.");
|
|
|
+ if (Math::is_equal_approx(time_horizon_obstacles, p_time_horizon)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ time_horizon_obstacles = p_time_horizon;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_time_horizon_obstacles(agent, time_horizon_obstacles);
|
|
|
}
|
|
|
|
|
|
void NavigationAgent3D::set_max_speed(real_t p_max_speed) {
|
|
|
+ ERR_FAIL_COND_MSG(p_max_speed < 0.0, "Max speed must be positive.");
|
|
|
if (Math::is_equal_approx(max_speed, p_max_speed)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
max_speed = p_max_speed;
|
|
|
|
|
|
NavigationServer3D::get_singleton()->agent_set_max_speed(agent, max_speed);
|
|
@@ -509,7 +611,7 @@ Vector3 NavigationAgent3D::get_next_path_position() {
|
|
|
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, Vector3(), "The agent has no parent.");
|
|
|
return agent_parent->get_global_position();
|
|
|
} else {
|
|
|
- return navigation_path[navigation_path_index] - Vector3(0, navigation_height_offset, 0);
|
|
|
+ return navigation_path[navigation_path_index] - Vector3(0, path_height_offset, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -541,28 +643,26 @@ Vector3 NavigationAgent3D::get_final_position() {
|
|
|
return navigation_path[navigation_path.size() - 1];
|
|
|
}
|
|
|
|
|
|
-void NavigationAgent3D::set_velocity(Vector3 p_velocity) {
|
|
|
+void NavigationAgent3D::set_velocity_forced(Vector3 p_velocity) {
|
|
|
// Intentionally not checking for equality of the parameter.
|
|
|
// We need to always submit the velocity to the navigation server, even when it is the same, in order to run avoidance every frame.
|
|
|
// Revisit later when the navigation server can update avoidance without users resubmitting the velocity.
|
|
|
|
|
|
- target_velocity = p_velocity;
|
|
|
- velocity_submitted = true;
|
|
|
+ velocity_forced = p_velocity;
|
|
|
+ velocity_forced_submitted = true;
|
|
|
+}
|
|
|
|
|
|
- NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, target_velocity);
|
|
|
- NavigationServer3D::get_singleton()->agent_set_velocity(agent, prev_safe_velocity);
|
|
|
+void NavigationAgent3D::set_velocity(const Vector3 p_velocity) {
|
|
|
+ velocity = p_velocity;
|
|
|
+ velocity_submitted = true;
|
|
|
}
|
|
|
|
|
|
void NavigationAgent3D::_avoidance_done(Vector3 p_new_velocity) {
|
|
|
- prev_safe_velocity = p_new_velocity;
|
|
|
-
|
|
|
- if (!velocity_submitted) {
|
|
|
- target_velocity = Vector3();
|
|
|
- return;
|
|
|
+ safe_velocity = p_new_velocity;
|
|
|
+ if (!use_3d_avoidance) {
|
|
|
+ safe_velocity.y = stored_y_velocity;
|
|
|
}
|
|
|
- velocity_submitted = false;
|
|
|
-
|
|
|
- emit_signal(SNAME("velocity_computed"), p_new_velocity);
|
|
|
+ emit_signal(SNAME("velocity_computed"), safe_velocity);
|
|
|
}
|
|
|
|
|
|
PackedStringArray NavigationAgent3D::get_configuration_warnings() const {
|
|
@@ -585,9 +685,6 @@ void NavigationAgent3D::update_navigation() {
|
|
|
if (!target_position_submitted) {
|
|
|
return;
|
|
|
}
|
|
|
- if (update_frame_id == Engine::get_singleton()->get_physics_frames()) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
update_frame_id = Engine::get_singleton()->get_physics_frames();
|
|
|
|
|
@@ -607,8 +704,8 @@ void NavigationAgent3D::update_navigation() {
|
|
|
Vector3 segment[2];
|
|
|
segment[0] = navigation_path[navigation_path_index - 1];
|
|
|
segment[1] = navigation_path[navigation_path_index];
|
|
|
- segment[0].y -= navigation_height_offset;
|
|
|
- segment[1].y -= navigation_height_offset;
|
|
|
+ segment[0].y -= path_height_offset;
|
|
|
+ segment[1].y -= path_height_offset;
|
|
|
Vector3 p = Geometry3D::get_closest_point_to_segment(origin, segment);
|
|
|
if (origin.distance_to(p) >= path_max_distance) {
|
|
|
// To faraway, reload path
|
|
@@ -650,7 +747,7 @@ void NavigationAgent3D::update_navigation() {
|
|
|
const TypedArray<RID> &navigation_path_rids = navigation_result->get_path_rids();
|
|
|
const Vector<int64_t> &navigation_path_owners = navigation_result->get_path_owner_ids();
|
|
|
|
|
|
- while (origin.distance_to(navigation_path[navigation_path_index] - Vector3(0, navigation_height_offset, 0)) < path_desired_distance) {
|
|
|
+ while (origin.distance_to(navigation_path[navigation_path_index] - Vector3(0, path_height_offset, 0)) < path_desired_distance) {
|
|
|
Dictionary details;
|
|
|
|
|
|
const Vector3 waypoint = navigation_path[navigation_path_index];
|
|
@@ -735,6 +832,71 @@ void NavigationAgent3D::_check_distance_to_target() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void NavigationAgent3D::set_avoidance_layers(uint32_t p_layers) {
|
|
|
+ avoidance_layers = p_layers;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_layers(get_rid(), avoidance_layers);
|
|
|
+}
|
|
|
+
|
|
|
+uint32_t NavigationAgent3D::get_avoidance_layers() const {
|
|
|
+ return avoidance_layers;
|
|
|
+}
|
|
|
+
|
|
|
+void NavigationAgent3D::set_avoidance_mask(uint32_t p_mask) {
|
|
|
+ avoidance_mask = p_mask;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_mask(get_rid(), avoidance_mask);
|
|
|
+}
|
|
|
+
|
|
|
+uint32_t NavigationAgent3D::get_avoidance_mask() const {
|
|
|
+ return avoidance_mask;
|
|
|
+}
|
|
|
+
|
|
|
+void NavigationAgent3D::set_avoidance_layer_value(int p_layer_number, bool p_value) {
|
|
|
+ ERR_FAIL_COND_MSG(p_layer_number < 1, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
+ ERR_FAIL_COND_MSG(p_layer_number > 32, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
+ uint32_t avoidance_layers_new = get_avoidance_layers();
|
|
|
+ if (p_value) {
|
|
|
+ avoidance_layers_new |= 1 << (p_layer_number - 1);
|
|
|
+ } else {
|
|
|
+ avoidance_layers_new &= ~(1 << (p_layer_number - 1));
|
|
|
+ }
|
|
|
+ set_avoidance_layers(avoidance_layers_new);
|
|
|
+}
|
|
|
+
|
|
|
+bool NavigationAgent3D::get_avoidance_layer_value(int p_layer_number) const {
|
|
|
+ ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
+ ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
+ return get_avoidance_layers() & (1 << (p_layer_number - 1));
|
|
|
+}
|
|
|
+
|
|
|
+void NavigationAgent3D::set_avoidance_mask_value(int p_mask_number, bool p_value) {
|
|
|
+ ERR_FAIL_COND_MSG(p_mask_number < 1, "Avoidance mask number must be between 1 and 32 inclusive.");
|
|
|
+ ERR_FAIL_COND_MSG(p_mask_number > 32, "Avoidance mask number must be between 1 and 32 inclusive.");
|
|
|
+ uint32_t mask = get_avoidance_mask();
|
|
|
+ if (p_value) {
|
|
|
+ mask |= 1 << (p_mask_number - 1);
|
|
|
+ } else {
|
|
|
+ mask &= ~(1 << (p_mask_number - 1));
|
|
|
+ }
|
|
|
+ set_avoidance_mask(mask);
|
|
|
+}
|
|
|
+
|
|
|
+bool NavigationAgent3D::get_avoidance_mask_value(int p_mask_number) const {
|
|
|
+ ERR_FAIL_COND_V_MSG(p_mask_number < 1, false, "Avoidance mask number must be between 1 and 32 inclusive.");
|
|
|
+ ERR_FAIL_COND_V_MSG(p_mask_number > 32, false, "Avoidance mask number must be between 1 and 32 inclusive.");
|
|
|
+ return get_avoidance_mask() & (1 << (p_mask_number - 1));
|
|
|
+}
|
|
|
+
|
|
|
+void NavigationAgent3D::set_avoidance_priority(real_t p_priority) {
|
|
|
+ ERR_FAIL_COND_MSG(p_priority < 0.0, "Avoidance priority must be between 0.0 and 1.0 inclusive.");
|
|
|
+ ERR_FAIL_COND_MSG(p_priority > 1.0, "Avoidance priority must be between 0.0 and 1.0 inclusive.");
|
|
|
+ avoidance_priority = p_priority;
|
|
|
+ NavigationServer3D::get_singleton()->agent_set_avoidance_priority(get_rid(), p_priority);
|
|
|
+}
|
|
|
+
|
|
|
+real_t NavigationAgent3D::get_avoidance_priority() const {
|
|
|
+ return avoidance_priority;
|
|
|
+}
|
|
|
+
|
|
|
////////DEBUG////////////////////////////////////////////////////////////
|
|
|
|
|
|
void NavigationAgent3D::set_debug_enabled(bool p_enabled) {
|