feat: added hurt state for player
This commit is contained in:
parent
2054474c01
commit
c7b9f97b70
10 changed files with 58 additions and 37 deletions
|
|
@ -32,61 +32,67 @@ void Enemy::chase_enter() {
|
|||
}
|
||||
|
||||
void Enemy::chase() {
|
||||
bool const is_chasing{!this->agent->is_navigation_finished()};
|
||||
this->anim_tree->set_lock_running(is_chasing);
|
||||
this->anim_tree->set_aim_weapon(!is_chasing);
|
||||
if(is_chasing) {
|
||||
bool const at_end{!this->agent->is_navigation_finished()};
|
||||
this->anim_tree->set_lock_running(at_end);
|
||||
this->anim_tree->set_aim_weapon(!at_end);
|
||||
if(at_end) {
|
||||
gd::Vector3 const global_pos{this->get_global_position()};
|
||||
gd::Vector3 const target{global_pos * 2 - this->agent->get_next_path_position()};
|
||||
this->look_at({target.x, global_pos.y, target.z});
|
||||
}
|
||||
if(this->get_global_position().distance_to(this->player->get_global_position()) >= this->agent->get_target_desired_distance())
|
||||
} else if(this->get_global_position().distance_to(this->player->get_global_position()) >= this->agent->get_target_desired_distance())
|
||||
this->chase_enter(); // repath
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::miss_enter() {
|
||||
Enemy::ActionFn Enemy::wait_line_of_sight() {
|
||||
if(this->can_see_player)
|
||||
return (ActionFn)&Enemy::take_aim;
|
||||
else
|
||||
return (ActionFn)&Enemy::wait_line_of_sight;
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::take_aim() {
|
||||
this->anim_tree->set_aim_weapon(true);
|
||||
return (ActionFn)&Enemy::miss;
|
||||
if(this->anim_tree->get_current_state().begins_with("Aim"))
|
||||
return (ActionFn)&Enemy::hit;
|
||||
else
|
||||
return(ActionFn)&Enemy::take_aim;
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::miss() {
|
||||
if(this->anim_tree->get_current_state().begins_with("Fire") || this->anim_tree->get_fire_weapon()) // last shot still going
|
||||
return (ActionFn)&Enemy::miss;
|
||||
if(this->can_see_player) {
|
||||
gd::Basis const basis{this->get_global_basis()};
|
||||
this->look_at(this->get_global_position() * 2 - this->player->get_global_position() + basis.get_column(0));
|
||||
this->look_at(this->get_global_position() * 2 - this->player->get_global_position() + basis.get_column(0) * 0.6f);
|
||||
this->anim_tree->set_aim_weapon(true);
|
||||
this->anim_tree->set_fire_weapon();
|
||||
if(this->anim_tree->get_fire_weapon()) {
|
||||
gd::UtilityFunctions::print("!!! miss fired");
|
||||
return ++this->missed_shots > SHOTS_BEFORE_HIT ? (ActionFn)&Enemy::hit_enter : (ActionFn)&Enemy::miss_enter;
|
||||
}
|
||||
++this->missed_shots;
|
||||
return (ActionFn)&Enemy::wait_end_of_shot;
|
||||
} else {
|
||||
this->chase();
|
||||
}
|
||||
return (ActionFn)&Enemy::miss;
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::hit_enter() {
|
||||
this->anim_tree->set_aim_weapon(true);
|
||||
return (ActionFn)&Enemy::hit;
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::hit() {
|
||||
if(this->anim_tree->get_current_state().begins_with("Fire") || this->anim_tree->get_fire_weapon()) // last shot still going
|
||||
return (ActionFn)&Enemy::hit;
|
||||
else if(this->can_see_player) {
|
||||
if(this->can_see_player) {
|
||||
this->look_at(this->get_global_position() * 2 - this->player->get_global_position());
|
||||
this->anim_tree->set_aim_weapon(true);
|
||||
this->anim_tree->set_fire_weapon();
|
||||
this->missed_shots = 0;
|
||||
return (ActionFn)&Enemy::miss_enter;
|
||||
return (ActionFn)&Enemy::wait_end_of_shot;
|
||||
} else {
|
||||
this->chase();
|
||||
}
|
||||
return (ActionFn)&Enemy::hit;
|
||||
}
|
||||
|
||||
Enemy::ActionFn Enemy::wait_end_of_shot() {
|
||||
if(this->anim_tree->get_current_state().begins_with("Fire") || this->anim_tree->get_fire_weapon()) // last shot still going
|
||||
return (ActionFn)&Enemy::wait_end_of_shot;
|
||||
else
|
||||
return this->missed_shots >= SHOTS_BEFORE_HIT ? (ActionFn)&Enemy::hit : (ActionFn)&Enemy::miss;
|
||||
|
||||
}
|
||||
|
||||
void Enemy::_physics_process(double delta) {
|
||||
this->update_can_see_player();
|
||||
gd::Basis const basis{this->get_global_basis()};
|
||||
|
|
@ -95,7 +101,7 @@ void Enemy::_physics_process(double delta) {
|
|||
basis.get_column(0) * motion.x +
|
||||
basis.get_column(1) * motion.y +
|
||||
basis.get_column(2) * motion.z
|
||||
});
|
||||
});\
|
||||
this->move_and_slide();
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +113,7 @@ void Enemy::damage() {
|
|||
|
||||
void Enemy::notice_player(Player *player) {
|
||||
this->player = player;
|
||||
this->current_action_fn = (ActionFn)&Enemy::miss_enter;
|
||||
this->current_action_fn = (ActionFn)&Enemy::wait_line_of_sight;
|
||||
}
|
||||
|
||||
void Enemy::update_can_see_player() {
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@ public:
|
|||
void update();
|
||||
void chase_enter();
|
||||
void chase();
|
||||
ActionFn miss_enter();
|
||||
ActionFn wait_line_of_sight();
|
||||
ActionFn take_aim();
|
||||
ActionFn miss();
|
||||
ActionFn hit_enter();
|
||||
ActionFn hit();
|
||||
ActionFn stab_enter();
|
||||
ActionFn stab();
|
||||
ActionFn wait_end_of_shot();
|
||||
virtual void _physics_process(double delta) override;
|
||||
virtual void damage() override;
|
||||
|
||||
|
|
@ -34,10 +35,10 @@ public:
|
|||
void set_update_interval(float time);
|
||||
float get_update_interval() const;
|
||||
private:
|
||||
int const SHOTS_BEFORE_HIT{2};
|
||||
int const SHOTS_BEFORE_HIT{1};
|
||||
|
||||
int missed_shots{0};
|
||||
double update_interval{0.2};
|
||||
double update_interval{0.4};
|
||||
ActionFn current_action_fn{nullptr};
|
||||
bool can_see_player{false};
|
||||
Player *player{nullptr};
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void Player::_physics_process(double delta [[maybe_unused]]) {
|
|||
}
|
||||
|
||||
void Player::damage() {
|
||||
this->anim_tree->death_animation();
|
||||
this->anim_tree->hit_animation();
|
||||
}
|
||||
|
||||
void Player::process_transform_camera(double delta) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,10 @@ bool PlayerAnimTree::get_stab() {
|
|||
return is_set;
|
||||
}
|
||||
|
||||
void PlayerAnimTree::hit_animation() {
|
||||
this->fsm->start("Hit", true);
|
||||
}
|
||||
|
||||
void PlayerAnimTree::death_animation() {
|
||||
this->set("parameters/DeathSeek/request", 0.f);
|
||||
this->is_dead = true;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ public:
|
|||
bool get_fire_weapon();
|
||||
void set_stab();
|
||||
bool get_stab();
|
||||
void hit_animation();
|
||||
void death_animation();
|
||||
bool match_tags(Tags tags) const;
|
||||
gd::StringName const &get_current_state() const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue