feat: comment pass on player animation tree class

main
Sara 2024-12-07 16:55:17 +01:00
parent ff0199a342
commit c65a059ffd
2 changed files with 26 additions and 22 deletions

View File

@ -20,17 +20,21 @@ void PlayerAnimTree::_ready() {
void PlayerAnimTree::_process(double delta) {
if(gd::Engine::get_singleton()->is_editor_hint())
return;
this->turn_speed = gd::Math::move_toward(this->turn_speed, this->target_turn_speed, float(delta * 30.));
this->commit_turn_speed();
this->update_tags(this->fsm->get_current_node());
// update timers
this->fire_weapon -= delta;
this->running_time -= delta;
// increase death counter
if(this->is_dead && this->death_blend < 1.f) {
this->death_blend = gd::Math::min(this->death_blend + float(delta * this->DEATH_BLEND_SPEED), 1.f);
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.));
// 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) {

View File

@ -12,9 +12,9 @@ class PlayerAnimTree : public gd::AnimationTree {
static void _bind_methods();
public:
enum Tags : unsigned {
None = 0x0,
Turn = 0x1,
Aim = 0x2
None = 0x0, //!< don't apply any state-specific logic
Turn = 0x1, //!< allow turning of the character
Aim = 0x2 //!< (player only) slow down camera movement when aiming
};
public:
virtual void _ready() override;
@ -39,23 +39,23 @@ private:
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 RUN_PARAM_DECAY{0.25}; //!< how many seconds to run every time set_is_running is called
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 RUN_PARAM_DECAY{0.25}; //!< how many seconds to run every time set_is_running is called.
gd::Node3D *parent_3d{nullptr};
gd::Ref<gd::AnimationNodeStateMachinePlayback> fsm;
float turn_speed{0.f};
float target_turn_speed{0.f};
bool is_walking{false};
float walk_speed{0.f};
double running_time{0.0};
bool aim_weapon{false};
double fire_weapon{0.0};
float death_blend{0.f};
bool is_dead{false};
Tags current_tags{Tags::None};
gd::StringName last_known_anim{};
gd::Node3D *parent_3d{nullptr}; //!< immediate parent as Node3D, rotational root motion is applied to this.
gd::Ref<gd::AnimationNodeStateMachinePlayback> fsm{}; //!< actions state machine from animation blend tree.
float turn_speed{0.f}; //!< blend position of turn animation (-1 to 1). Moved towards target_turn_speed every frame.
float target_turn_speed{0.f}; //!< target blend position of turn animation.
bool is_walking{false}; //!< set to true if the walk animation should be playing.
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.
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.
gd::StringName last_known_anim{}; //!< last known animation state in action state machine.
};
#endif // !PLAYER_ANIM_HPP