From f048e97edec42930bace1748dd646ab1a04c3fc3 Mon Sep 17 00:00:00 2001 From: Sara Date: Sat, 4 Jan 2025 23:43:46 +0100 Subject: [PATCH] fix: enemies detecting player too early --- src/enemy.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/enemy.cpp b/src/enemy.cpp index c9d9c60..4bb9e10 100644 --- a/src/enemy.cpp +++ b/src/enemy.cpp @@ -66,7 +66,8 @@ void Enemy::update() { Enemy::ActionFn Enemy::wait_line_of_sight() { this->set_current_state_name("Guard"); - if(this->get_global_position().distance_squared_to(this->player->get_global_position()) < this->STAB_RANGE * this->STAB_RANGE) + this->anim_tree->set_aim_weapon(false); + if(this->can_see_player && this->get_global_position().distance_squared_to(this->player->get_global_position()) < this->STAB_RANGE * this->STAB_RANGE) return (ActionFn)&Enemy::stab; else if(this->can_see_player) return (ActionFn)&Enemy::take_aim; @@ -191,7 +192,7 @@ void Enemy::update_can_see_player() { gd::Vector3 const target{this->player->get_global_position() + gd::Vector3{0.f, 1.8f, 0.f}}; // check if the target is in field of view float const dot{(target - origin).normalized().dot(this->get_global_basis().get_column(2))}; - if(this->current_action_fn != (ActionFn)&Enemy::chase_player && dot <= 0.2f && target.distance_to(origin) > 4.f) { + if(this->current_action_fn != (ActionFn)&Enemy::chase_player && dot <= 0.2f && target.distance_to(origin) > 1.5f * 1.5f) { this->can_see_player = false; // target not in field of view } else { // check if the sightline is obstructed by raycast