chore: added repath delay to chase state
This commit is contained in:
parent
300cac9dd3
commit
d31eda3752
2 changed files with 13 additions and 1 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue