From e2fd645a428bbc3115e4dfea014a40c100b191c6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 4 Sep 2023 17:38:32 +0200 Subject: [PATCH] Ported from godot4: Fix NavigationAgent position not always updating Fixes NavigationAgent position not always updating. - smix8 https://github.com/godotengine/godot/commit/34bc410fb419cb002dbe6cd676f0ff54fab5db9c --- scene/2d/navigation_agent_2d.cpp | 5 ++++- scene/3d/navigation_agent.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index e51334dc9..78edb2893 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -255,11 +255,14 @@ void NavigationAgent2D::_notification(int p_what) { #endif // DEBUG_ENABLED } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { + if (agent_parent && avoidance_enabled) { + Navigation2DServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_position()); + } + if (agent_parent && target_position_submitted) { if (velocity_submitted) { velocity_submitted = false; if (avoidance_enabled) { - Navigation2DServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_position()); Navigation2DServer::get_singleton()->agent_set_velocity(agent, velocity); } } diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent.cpp index db1813a29..01b0b8c7b 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent.cpp @@ -267,11 +267,14 @@ void NavigationAgent::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { + if (agent_parent && avoidance_enabled) { + NavigationServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin); + } + if (agent_parent && target_position_submitted) { if (velocity_submitted) { velocity_submitted = false; if (avoidance_enabled) { - NavigationServer::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;