You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-07 19:53:17 +00:00
put distance check to target into function
put distance check to target into function
This commit is contained in:
@@ -100,12 +100,7 @@ void NavigationAgent2D::_notification(int p_what) {
|
||||
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) {
|
||||
emit_signal("target_reached");
|
||||
target_reached = true;
|
||||
}
|
||||
}
|
||||
_check_distance_to_target();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -301,12 +296,7 @@ void NavigationAgent2D::update_navigation() {
|
||||
while (o.distance_to(navigation_path[nav_path_index]) < target_desired_distance) {
|
||||
nav_path_index += 1;
|
||||
if (nav_path_index == navigation_path.size()) {
|
||||
if (!target_reached) {
|
||||
if (distance_to_target() < target_desired_distance) {
|
||||
emit_signal("target_reached");
|
||||
target_reached = true;
|
||||
}
|
||||
}
|
||||
_check_distance_to_target();
|
||||
nav_path_index -= 1;
|
||||
navigation_finished = true;
|
||||
emit_signal("navigation_finished");
|
||||
@@ -315,3 +305,12 @@ void NavigationAgent2D::update_navigation() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationAgent2D::_check_distance_to_target() {
|
||||
if (!target_reached) {
|
||||
if (distance_to_target() < target_desired_distance) {
|
||||
emit_signal("target_reached");
|
||||
target_reached = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
|
||||
private:
|
||||
void update_navigation();
|
||||
void _check_distance_to_target();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user