summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-02-09 10:13:35 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-02-09 10:13:35 +0100
commitd69809cab603cae9f525768337affe5e12e454a8 (patch)
tree2d8d6aeaf1f0cc214ab26fb913d46a0585fb8fb4
parentedae21f3aa3391e1d0e1cb0998ecc2c82d2adf39 (diff)
parent097f8a5fdb9b8fc5fc455356fab851439c06f35f (diff)
Merge pull request #72947 from DarkKilauea/nav-fix-avoidance-callback
Fix missing avoidance updates when using same velocity
-rw-r--r--scene/2d/navigation_agent_2d.cpp11
-rw-r--r--scene/3d/navigation_agent_3d.cpp11
2 files changed, 10 insertions, 12 deletions
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 6f1df7afd3..6aa7779b09 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -434,9 +434,8 @@ real_t NavigationAgent2D::get_path_max_distance() {
}
void NavigationAgent2D::set_target_position(Vector2 p_position) {
- if (target_position.is_equal_approx(p_position)) {
- return;
- }
+ // Intentionally not checking for equality of the parameter, as we want to update the path even if the target position is the same in case the world changed.
+ // Revisit later when the navigation server can update the path without requesting a new path.
target_position = p_position;
target_position_submitted = true;
@@ -489,9 +488,9 @@ Vector2 NavigationAgent2D::get_final_position() {
}
void NavigationAgent2D::set_velocity(Vector2 p_velocity) {
- if (target_velocity.is_equal_approx(p_velocity)) {
- return;
- }
+ // 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;
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index 47c68721d4..081e7505d0 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -459,9 +459,8 @@ real_t NavigationAgent3D::get_path_max_distance() {
}
void NavigationAgent3D::set_target_position(Vector3 p_position) {
- if (target_position.is_equal_approx(p_position)) {
- return;
- }
+ // Intentionally not checking for equality of the parameter, as we want to update the path even if the target position is the same in case the world changed.
+ // Revisit later when the navigation server can update the path without requesting a new path.
target_position = p_position;
target_position_submitted = true;
@@ -514,9 +513,9 @@ Vector3 NavigationAgent3D::get_final_position() {
}
void NavigationAgent3D::set_velocity(Vector3 p_velocity) {
- if (target_velocity.is_equal_approx(p_velocity)) {
- return;
- }
+ // 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;