2024-12-04 15:15:40 +00:00
# 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>
2024-12-06 16:12:06 +00:00
# include <godot_cpp/classes/animation_tree.hpp>
# include <godot_cpp/classes/node3d.hpp>
2024-12-04 15:15:40 +00:00
namespace gd = godot ;
class PlayerAnimTree : public gd : : AnimationTree {
GDCLASS ( PlayerAnimTree , gd : : AnimationTree ) ;
static void _bind_methods ( ) ;
public :
enum Tags : unsigned {
2024-12-07 15:55:17 +00:00
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
2024-12-04 15:15:40 +00:00
} ;
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 ;
2024-12-09 22:55:11 +00:00
void set_lock_running ( bool value ) ;
bool get_lock_running ( ) const ;
2024-12-04 15:15:40 +00:00
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 ( ) ;
2024-12-07 16:44:39 +00:00
void set_stab ( ) ;
bool get_stab ( ) ;
2024-12-10 19:05:13 +00:00
void hit_animation ( ) ;
2024-12-06 16:12:06 +00:00
void death_animation ( ) ;
2024-12-07 16:44:39 +00:00
bool match_tags ( Tags tags ) const ;
2024-12-09 22:55:11 +00:00
gd : : StringName const & get_current_state ( ) const ;
2024-12-04 15:15:40 +00:00
private :
void update_tags ( gd : : StringName const & anim ) ;
void commit_turn_speed ( ) ;
void commit_walk_speed ( ) ;
private :
2024-12-07 15:55:17 +00:00
double const DEATH_BLEND_SPEED { 1. / 0.3 } ; //!< multiplier for delta_time when blending from state machine to death animation.
2024-12-07 16:44:39 +00:00
double const BUTTON_PARAM_DECAY { 0.1 } ; //!< how many seconds it takes for a fire input to become invalid.
2024-12-07 15:55:17 +00:00
double const RUN_PARAM_DECAY { 0.25 } ; //!< how many seconds to run every time set_is_running is called.
2024-12-06 16:12:06 +00:00
2024-12-07 15:55:17 +00:00
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.
2024-12-09 22:55:11 +00:00
bool lock_running { false } ; //!< lock animation into running instead of walking.
2024-12-07 15:55:17 +00:00
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.
2024-12-07 16:44:39 +00:00
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.
2024-12-07 15:55:17 +00:00
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.
2024-12-04 15:15:40 +00:00
} ;
# endif // !PLAYER_ANIM_HPP