From d31eda37521b7066db16fd667140dffd920d4979 Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 12 Feb 2026 18:28:59 +0100 Subject: [PATCH] chore: added repath delay to chase state --- modules/wave_survival/enemy_body.cpp | 11 ++++++++++- modules/wave_survival/enemy_body.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/wave_survival/enemy_body.cpp b/modules/wave_survival/enemy_body.cpp index f5244667..09a673fd 100644 --- a/modules/wave_survival/enemy_body.cpp +++ b/modules/wave_survival/enemy_body.cpp @@ -1,4 +1,5 @@ #include "enemy_body.h" +#include "core/math/math_funcs.h" #include "macros.h" #include "scene/animation/animation_player.h" #include "wave_survival/npc_unit.h" @@ -190,6 +191,10 @@ void EnemyPatrolState::exit_state() { } void EnemyChaseState::enter_state() { + static int repath_frames_start{ 0 }; + this->repath_frames = repath_frames_start; + repath_frames_start = (repath_frames_start + 1) % 5; + get_body()->set_movement_speed(get_body()->get_max_speed()); get_nav()->set_max_speed(get_body()->get_max_speed()); get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position()); @@ -198,7 +203,11 @@ void EnemyChaseState::enter_state() { void EnemyChaseState::process(double delta) { // TODO: optimize this with some checks to avoid re-pathing every frame - get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position()); + --this->repath_frames; + if (this->repath_frames < 0) { + get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position()); + this->repath_frames = 5; + } Vector3 const direction{ get_body()->get_global_position().direction_to(get_nav()->get_next_path_position()) }; get_body()->set_movement_direction(Vector2{ direction.x, direction.z }.normalized()); } diff --git a/modules/wave_survival/enemy_body.h b/modules/wave_survival/enemy_body.h index a2172fd5..9021acc2 100644 --- a/modules/wave_survival/enemy_body.h +++ b/modules/wave_survival/enemy_body.h @@ -97,6 +97,9 @@ class EnemyChaseState : public EnemyState { public: virtual void enter_state() override; virtual void process(double delta) override; + +private: + int repath_frames{ 0 }; }; #endif // !ENEMY_BODY_H