70 lines
3.4 KiB
C++
70 lines
3.4 KiB
C++
#ifndef PLAYER_ANIM_TREE_HPP
|
|
#define PLAYER_ANIM_TREE_HPP
|
|
|
|
#include "utils/godot_macros.hpp"
|
|
#include <godot_cpp/classes/animation_node_state_machine_playback.hpp>
|
|
#include <godot_cpp/classes/animation_tree.hpp>
|
|
#include <godot_cpp/classes/node3d.hpp>
|
|
namespace gd = godot;
|
|
|
|
class PlayerAnimTree : public gd::AnimationTree {
|
|
GDCLASS(PlayerAnimTree, gd::AnimationTree);
|
|
static void _bind_methods();
|
|
public:
|
|
enum Tags : unsigned {
|
|
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;
|
|
virtual void _process(double delta) override;
|
|
|
|
void set_target_turn_speed(float value);
|
|
float get_target_turn_speed() const;
|
|
void set_is_walking(bool value);
|
|
bool get_is_walking() const;
|
|
void set_walk_speed(float value);
|
|
float get_walk_speed() const;
|
|
void set_lock_running(bool value);
|
|
bool get_lock_running() const;
|
|
void set_is_running();
|
|
bool get_is_running() const;
|
|
void set_aim_weapon(bool value);
|
|
bool get_aim_weapon() const;
|
|
void set_fire_weapon();
|
|
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;
|
|
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 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.
|
|
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.
|
|
bool lock_running{false}; //!< lock animation into running instead of walking.
|
|
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 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.
|
|
gd::StringName last_known_anim{}; //!< last known animation state in action state machine.
|
|
};
|
|
|
|
#endif // !PLAYER_ANIM_HPP
|