diff options
Diffstat (limited to 'scene/2d/navigation_agent_2d.cpp')
-rw-r--r-- | scene/2d/navigation_agent_2d.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index dfeb5eea45..cb2dbba0fe 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -35,7 +35,6 @@ #include "servers/navigation_server_2d.h" void NavigationAgent2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent2D::set_target_desired_distance); ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent2D::get_target_desired_distance); @@ -91,7 +90,6 @@ void NavigationAgent2D::_bind_methods() { void NavigationAgent2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - agent_parent = Object::cast_to<Node2D>(get_parent()); NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); @@ -102,10 +100,11 @@ void NavigationAgent2D::_notification(int p_what) { Node *p = get_parent(); while (p != nullptr) { nav = Object::cast_to<Navigation2D>(p); - if (nav != nullptr) + if (nav != nullptr) { p = nullptr; - else + } else { p = p->get_parent(); + } } set_navigation(nav); @@ -120,7 +119,6 @@ void NavigationAgent2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (agent_parent) { - NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin()); if (!target_reached) { if (distance_to_target() < target_desired_distance) { @@ -148,8 +146,9 @@ NavigationAgent2D::~NavigationAgent2D() { } void NavigationAgent2D::set_navigation(Navigation2D *p_nav) { - if (navigation == p_nav) + if (navigation == p_nav) { return; // Pointless + } navigation = p_nav; NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); @@ -279,13 +278,15 @@ String NavigationAgent2D::get_configuration_warning() const { } void NavigationAgent2D::update_navigation() { - - if (agent_parent == nullptr) + if (agent_parent == nullptr) { return; - if (navigation == nullptr) + } + if (navigation == nullptr) { return; - if (update_frame_id == Engine::get_singleton()->get_physics_frames()) + } + if (update_frame_id == Engine::get_singleton()->get_physics_frames()) { return; + } update_frame_id = Engine::get_singleton()->get_physics_frames(); @@ -318,8 +319,9 @@ void NavigationAgent2D::update_navigation() { emit_signal("path_changed"); } - if (navigation_path.size() == 0) + if (navigation_path.size() == 0) { return; + } // Check if we can advance the navigation path if (navigation_finished == false) { |