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) {
if(this->nav_agent->is_navigation_finished()) {
this->move(Vector3());
} else {
float const distance = this->nav_agent->get_target_position().distance_squared_to(this->get_global_position());
float const target_distance_sqr = std::pow(this->nav_agent->get_target_desired_distance(), 2.f);
if(!this->nav_agent->is_navigation_finished() && distance >= target_distance_sqr) {
Vector3 const target_position = this->nav_agent->get_next_path_position();
Vector3 const direction = (target_position - this->get_global_position()).normalized();
this->move(direction);