fix: player character now actually stops

This commit is contained in:
Sara 2024-03-22 15:34:53 +01:00
parent 4c521a0aa3
commit 9850fffb80

View file

@ -107,9 +107,9 @@ Vector3 PlayerCharacter::get_velocity_target() const {
} }
void PlayerCharacter::process_ai(double delta_time) { void PlayerCharacter::process_ai(double delta_time) {
if(this->nav_agent->is_navigation_finished()) { float const distance = this->nav_agent->get_target_position().distance_squared_to(this->get_global_position());
this->move(Vector3()); float const target_distance_sqr = std::pow(this->nav_agent->get_target_desired_distance(), 2.f);
} else { if(!this->nav_agent->is_navigation_finished() && distance >= target_distance_sqr) {
Vector3 const target_position = this->nav_agent->get_next_path_position(); Vector3 const target_position = this->nav_agent->get_next_path_position();
Vector3 const direction = (target_position - this->get_global_position()).normalized(); Vector3 const direction = (target_position - this->get_global_position()).normalized();
this->move(direction); this->move(direction);