Skip to content

Commit

Permalink
Fix NavigationObstacles not being added to avoidance simulation
Browse files Browse the repository at this point in the history
Fixes NavigationObstacles not being added to avoidance simulation.
  • Loading branch information
smix8 committed Apr 6, 2023
1 parent 92b7a96 commit aadf33e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scene/2d/navigation_obstacle_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,20 @@ void NavigationObstacle2D::set_agent_parent(Node *p_agent_parent) {
} else {
NavigationServer2D::get_singleton()->agent_set_map(get_rid(), parent_node2d->get_world_2d()->get_navigation_map());
}
// Need to register Callback as obstacle requires a valid Callback to be added to avoidance simulation.
NavigationServer2D::get_singleton()->agent_set_callback(get_rid(), callable_mp(this, &NavigationObstacle2D::_avoidance_done));
reevaluate_agent_radius();
} else {
parent_node2d = nullptr;
NavigationServer2D::get_singleton()->agent_set_map(get_rid(), RID());
NavigationServer2D::get_singleton()->agent_set_callback(agent, Callable());
}
}

void NavigationObstacle2D::_avoidance_done(Vector3 p_new_velocity) {
// Dummy function as obstacle requires a valid Callback to be added to avoidance simulation.
}

void NavigationObstacle2D::set_navigation_map(RID p_navigation_map) {
if (map_override == p_navigation_map) {
return;
Expand Down
2 changes: 2 additions & 0 deletions scene/2d/navigation_obstacle_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class NavigationObstacle2D : public Node {

PackedStringArray get_configuration_warnings() const override;

void _avoidance_done(Vector3 p_new_velocity); // Dummy

private:
void initialize_agent();
void reevaluate_agent_radius();
Expand Down
7 changes: 7 additions & 0 deletions scene/3d/navigation_obstacle_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,20 @@ void NavigationObstacle3D::set_agent_parent(Node *p_agent_parent) {
} else {
NavigationServer3D::get_singleton()->agent_set_map(get_rid(), parent_node3d->get_world_3d()->get_navigation_map());
}
// Need to register Callback as obstacle requires a valid Callback to be added to avoidance simulation.
NavigationServer3D::get_singleton()->agent_set_callback(get_rid(), callable_mp(this, &NavigationObstacle3D::_avoidance_done));
reevaluate_agent_radius();
} else {
parent_node3d = nullptr;
NavigationServer3D::get_singleton()->agent_set_map(get_rid(), RID());
NavigationServer3D::get_singleton()->agent_set_callback(agent, Callable());
}
}

void NavigationObstacle3D::_avoidance_done(Vector3 p_new_velocity) {
// Dummy function as obstacle requires a valid Callback to be added to avoidance simulation.
}

void NavigationObstacle3D::set_navigation_map(RID p_navigation_map) {
if (map_override == p_navigation_map) {
return;
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/navigation_obstacle_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class NavigationObstacle3D : public Node {

PackedStringArray get_configuration_warnings() const override;

void _avoidance_done(Vector3 p_new_velocity); // Dummy

private:
void initialize_agent();
void reevaluate_agent_radius();
Expand Down

0 comments on commit aadf33e

Please sign in to comment.