mirror of
https://github.com/godotengine/godot.git
synced 2024-10-23 21:51:35 +00:00
Merge pull request #47960 from smix8/issue_47334_navagent2d_target_reached
This commit is contained in:
commit
3a0cfd3d85
|
@ -104,12 +104,7 @@ void NavigationAgent2D::_notification(int p_what) {
|
||||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||||
if (agent_parent) {
|
if (agent_parent) {
|
||||||
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin());
|
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin());
|
||||||
if (!target_reached) {
|
_check_distance_to_target();
|
||||||
if (distance_to_target() < target_desired_distance) {
|
|
||||||
emit_signal("target_reached");
|
|
||||||
target_reached = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -305,6 +300,7 @@ void NavigationAgent2D::update_navigation() {
|
||||||
while (o.distance_to(navigation_path[nav_path_index]) < target_desired_distance) {
|
while (o.distance_to(navigation_path[nav_path_index]) < target_desired_distance) {
|
||||||
nav_path_index += 1;
|
nav_path_index += 1;
|
||||||
if (nav_path_index == navigation_path.size()) {
|
if (nav_path_index == navigation_path.size()) {
|
||||||
|
_check_distance_to_target();
|
||||||
nav_path_index -= 1;
|
nav_path_index -= 1;
|
||||||
navigation_finished = true;
|
navigation_finished = true;
|
||||||
emit_signal("navigation_finished");
|
emit_signal("navigation_finished");
|
||||||
|
@ -313,3 +309,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:
|
private:
|
||||||
void update_navigation();
|
void update_navigation();
|
||||||
|
void _check_distance_to_target();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user