feat: added stab button
This commit is contained in:
parent
b3cff8240b
commit
656525f76d
20 changed files with 1891 additions and 29 deletions
|
|
@ -85,8 +85,10 @@ void Player::_on_dir_vertical(gd::Ref<gd::InputEvent>, float value) {
|
|||
}
|
||||
|
||||
void Player::_on_fire(gd::Ref<gd::InputEvent> event, float) {
|
||||
if(event->is_pressed())
|
||||
if(event->is_pressed()) {
|
||||
this->anim_tree->set_fire_weapon();
|
||||
this->anim_tree->set_stab();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_on_run(gd::Ref<gd::InputEvent> event, float) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ void PlayerAnimTree::_bind_methods() {
|
|||
GDFUNCTION(get_is_running);
|
||||
GDPROPERTY(aim_weapon, gd::Variant::BOOL);
|
||||
GDFUNCTION(get_fire_weapon);
|
||||
GDFUNCTION(get_stab);
|
||||
}
|
||||
|
||||
void PlayerAnimTree::_ready() {
|
||||
|
|
@ -22,6 +23,7 @@ void PlayerAnimTree::_process(double delta) {
|
|||
return;
|
||||
// update timers
|
||||
this->fire_weapon -= delta;
|
||||
this->stab -= delta;
|
||||
this->running_time -= delta;
|
||||
// increase death counter
|
||||
if(this->is_dead && this->death_blend < 1.f) {
|
||||
|
|
@ -29,16 +31,18 @@ void PlayerAnimTree::_process(double delta) {
|
|||
this->set("parameters/DeathBlend/blend_amount", this->death_blend);
|
||||
}
|
||||
// turn speed smoothing
|
||||
this->turn_speed = gd::Math::move_toward(this->turn_speed, this->target_turn_speed, float(delta * 30.));
|
||||
if(this->match_tags(Tags::Turn)) {
|
||||
this->turn_speed = gd::Math::move_toward(this->turn_speed, this->target_turn_speed, float(delta * 20.));
|
||||
this->commit_turn_speed();
|
||||
}
|
||||
// rotational root motion
|
||||
this->parent_3d->set_quaternion(this->get_root_motion_rotation_accumulator());
|
||||
this->parent_3d->rotate_y(M_PIf);
|
||||
this->commit_turn_speed();
|
||||
this->update_tags(this->fsm->get_current_node());
|
||||
}
|
||||
|
||||
void PlayerAnimTree::set_target_turn_speed(float value) {
|
||||
this->target_turn_speed = value;
|
||||
this->target_turn_speed = gd::Math::clamp(value, -1.f, 1.f);
|
||||
}
|
||||
|
||||
float PlayerAnimTree::get_target_turn_speed() const {
|
||||
|
|
@ -79,12 +83,22 @@ bool PlayerAnimTree::get_aim_weapon() const {
|
|||
}
|
||||
|
||||
void PlayerAnimTree::set_fire_weapon() {
|
||||
this->fire_weapon = this->FIRE_PARAM_DECAY;
|
||||
this->fire_weapon = this->BUTTON_PARAM_DECAY;
|
||||
}
|
||||
|
||||
bool PlayerAnimTree::get_fire_weapon() {
|
||||
bool const is_set = this->fire_weapon > 0.f;
|
||||
this->fire_weapon = 0.f;
|
||||
bool const is_set{this->fire_weapon > 0.0};
|
||||
this->fire_weapon = 0.0;
|
||||
return is_set;
|
||||
}
|
||||
|
||||
void PlayerAnimTree::set_stab() {
|
||||
this->stab = this->BUTTON_PARAM_DECAY;
|
||||
}
|
||||
|
||||
bool PlayerAnimTree::get_stab() {
|
||||
bool const is_set{this->fire_weapon > 0.0};
|
||||
this->stab = 0.0;
|
||||
return is_set;
|
||||
}
|
||||
|
||||
|
|
@ -103,13 +117,15 @@ void PlayerAnimTree::update_tags(gd::StringName const &anim) {
|
|||
this->current_tags = Tags::None;
|
||||
if(anim.contains("[turn]"))
|
||||
this->current_tags = Tags(this->current_tags | Tags::Turn);
|
||||
else
|
||||
this->turn_speed = 0.f;
|
||||
if(anim.contains("[aim]"))
|
||||
this->current_tags = Tags(this->current_tags | Tags::Aim);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerAnimTree::commit_turn_speed() {
|
||||
this->set("parameters/Actions/Stationary [turn]/Turn/blend_position", this->turn_speed);
|
||||
this->set("parameters/Actions/Stationary [turn]/Turn/blend_position", gd::Math::abs(this->turn_speed)*this->turn_speed);
|
||||
}
|
||||
|
||||
void PlayerAnimTree::commit_walk_speed() {
|
||||
|
|
|
|||
|
|
@ -32,15 +32,17 @@ public:
|
|||
bool get_aim_weapon() const;
|
||||
void set_fire_weapon();
|
||||
bool get_fire_weapon();
|
||||
bool match_tags(Tags tags) const;
|
||||
void set_stab();
|
||||
bool get_stab();
|
||||
void death_animation();
|
||||
bool match_tags(Tags tags) const;
|
||||
private:
|
||||
void update_tags(gd::StringName const &anim);
|
||||
void commit_turn_speed();
|
||||
void commit_walk_speed();
|
||||
private:
|
||||
double const DEATH_BLEND_SPEED{1. / 0.3}; //!< multiplier for delta_time when blending from state machine to death animation.
|
||||
double const FIRE_PARAM_DECAY{0.5}; //!< how many seconds it takes for a fire input to become invalid.
|
||||
double const BUTTON_PARAM_DECAY{0.1}; //!< how many seconds it takes for a fire input to become invalid.
|
||||
double const RUN_PARAM_DECAY{0.25}; //!< how many seconds to run every time set_is_running is called.
|
||||
|
||||
gd::Node3D *parent_3d{nullptr}; //!< immediate parent as Node3D, rotational root motion is applied to this.
|
||||
|
|
@ -51,7 +53,8 @@ private:
|
|||
float walk_speed{0.f}; //!< blend amount between RESET/Rest animation and walk animation in walk state.
|
||||
double running_time{0.0}; //!< time in seconds to keep running for.
|
||||
bool aim_weapon{false}; //!< set to true to play the aim animation.
|
||||
double fire_weapon{0.0}; //!< play fire animation if this is > 0. Set to FIRE_PARAM_DECAY when set_fire_weapon is called. Decays by 'delta' every frame.
|
||||
double fire_weapon{0.0}; //!< play fire animation if this is > 0. Set to BUTTON_PARAM_DECAY when set_fire_weapon is called. Decays by 'delta' every frame.
|
||||
double stab{0.0}; //!< player stab animation if this is > 0. Set to BUTTON_PARAM_DECAY when set_stab is called. Decays by 'delta' every frame.
|
||||
float death_blend{0.f}; //!< current blend level of death animation. Quickly moved towards 1.0 when is_dead is set.
|
||||
bool is_dead{false}; //!< set to true to play death animation and tick up death_blend.
|
||||
Tags current_tags{Tags::None}; //!< tags (like [turn]) on the current action state.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue