summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2022-12-06 22:30:34 +0100
committersmix8 <52464204+smix8@users.noreply.github.com>2022-12-06 22:53:18 +0100
commit860379fc161698234b2757c6f62f8e05fa68ada8 (patch)
tree1ac77e809267d8b522f71d62d32450fdd407a41e /scene/2d
parentc241f1c52386b21cf2df936ee927740a06970db6 (diff)
Stop NavigationAgents without a target from moving to world origin
Stops NavigationAgents moving to the world origin without anyone telling them to do so.
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/navigation_agent_2d.cpp7
-rw-r--r--scene/2d/navigation_agent_2d.h1
2 files changed, 7 insertions, 1 deletions
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 1a62c9bb6c..aa32a27c70 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -161,7 +161,7 @@ void NavigationAgent2D::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- if (agent_parent) {
+ 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
@@ -314,6 +314,7 @@ real_t NavigationAgent2D::get_path_max_distance() {
void NavigationAgent2D::set_target_location(Vector2 p_location) {
target_location = p_location;
+ target_position_submitted = true;
_request_repath();
}
@@ -402,6 +403,9 @@ void NavigationAgent2D::update_navigation() {
if (!agent_parent->is_inside_tree()) {
return;
}
+ if (!target_position_submitted) {
+ return;
+ }
if (update_frame_id == Engine::get_singleton()->get_physics_frames()) {
return;
}
@@ -463,6 +467,7 @@ void NavigationAgent2D::update_navigation() {
_check_distance_to_target();
nav_path_index -= 1;
navigation_finished = true;
+ target_position_submitted = false;
emit_signal(SNAME("navigation_finished"));
break;
}
diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h
index 5abd3c0317..9f2d2e9ea7 100644
--- a/scene/2d/navigation_agent_2d.h
+++ b/scene/2d/navigation_agent_2d.h
@@ -60,6 +60,7 @@ class NavigationAgent2D : public Node {
real_t path_max_distance = 3.0;
Vector2 target_location;
+ bool target_position_submitted = false;
Ref<NavigationPathQueryParameters2D> navigation_query;
Ref<NavigationPathQueryResult2D> navigation_result;
int nav_path_index = 0;