feat: generalising of NPC logic
This commit is contained in:
parent
41bcf4cdf7
commit
1625a11c42
6 changed files with 74 additions and 37 deletions
|
|
@ -9,6 +9,7 @@
|
|||
class NpcUnit;
|
||||
class AnimationPlayer;
|
||||
class PatrolPath;
|
||||
class PlayerDetector;
|
||||
|
||||
class EnemyBody : public CharacterBody3D {
|
||||
GDCLASS(EnemyBody, CharacterBody3D);
|
||||
|
|
@ -33,6 +34,7 @@ public:
|
|||
NavigationAgent3D *get_nav() const;
|
||||
AnimationPlayer *get_anim() const;
|
||||
StateMachine *get_fsm() const;
|
||||
PlayerDetector *get_detector() const;
|
||||
|
||||
void set_movement_speed(float value);
|
||||
float get_movement_speed() const;
|
||||
|
|
@ -50,9 +52,12 @@ private:
|
|||
HealthStatus *health{ nullptr };
|
||||
NavigationAgent3D *nav{ nullptr };
|
||||
AnimationPlayer *anim{ nullptr };
|
||||
PlayerDetector *detector{ nullptr };
|
||||
Vector2 unit_offset{ 0, 0 };
|
||||
};
|
||||
|
||||
/* ============================== STATES ============================== */
|
||||
|
||||
class EnemyState : public State {
|
||||
GDCLASS(EnemyState, State);
|
||||
static void _bind_methods() {}
|
||||
|
|
@ -68,8 +73,8 @@ private:
|
|||
EnemyBody *body{ nullptr };
|
||||
};
|
||||
|
||||
class PatrolState : public EnemyState {
|
||||
GDCLASS(PatrolState, EnemyState);
|
||||
class EnemyPatrolState : public EnemyState {
|
||||
GDCLASS(EnemyPatrolState, EnemyState);
|
||||
static void _bind_methods() {}
|
||||
void set_patrol_target(Vector3 path_point);
|
||||
void on_velocity_calculated(Vector3 direction);
|
||||
|
|
@ -85,4 +90,13 @@ private:
|
|||
Callable mp_on_velocity_calculated{ callable_mp(this, &self_type::on_velocity_calculated) };
|
||||
};
|
||||
|
||||
class EnemyChaseState : public EnemyState {
|
||||
GDCLASS(EnemyChaseState, EnemyState);
|
||||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
virtual void enter_state() override;
|
||||
virtual void process(double delta) override;
|
||||
};
|
||||
|
||||
#endif // !ENEMY_BODY_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue