feat: created aim and fire animations
This commit is contained in:
parent
a7affe42ff
commit
be4fbb9d0b
13 changed files with 146 additions and 134 deletions
|
|
@ -5,33 +5,37 @@
|
|||
|
||||
void Player::_bind_methods() {
|
||||
#define CLASSNAME Player
|
||||
GDPROPERTY(input_directions, gd::Variant::VECTOR2);
|
||||
GDFUNCTION(get_input_directions);
|
||||
}
|
||||
|
||||
void Player::_ready() {
|
||||
if(gd::Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
this->anim_tree = this->get_node<gd::AnimationTree>("%AnimationTree");
|
||||
this->sfm = gd::Object::cast_to<gd::AnimationNodeStateMachinePlayback>(this->anim_tree->get("parameters/Actions/playback"));
|
||||
this->input = this->get_node<utils::PlayerInput>("%PlayerInput");
|
||||
this->input->listen_to(utils::PlayerInput::Listener("dir_left", "dir_right", callable_mp(this, &Player::_on_dir_horizontal)));
|
||||
this->input->listen_to(utils::PlayerInput::Listener("dir_backward", "dir_forward", callable_mp(this, &Player::_on_dir_vertical)));
|
||||
this->input->listen_to(utils::PlayerInput::Listener("look_left", "look_right", callable_mp(this, &Player::_on_look_horizontal)));
|
||||
this->input->listen_to(utils::PlayerInput::Listener("look_down", "look_up", callable_mp(this, &Player::_on_look_vertical)));
|
||||
this->input->listen_to(utils::PlayerInput::Listener("_mouse_left", "_mouse_right", callable_mp(this, &Player::_on_look_horizontal)));
|
||||
this->input->listen_to(utils::PlayerInput::Listener("_mouse_down", "_mouse_up", callable_mp(this, &Player::_on_look_vertical)));
|
||||
this->model_node = this->get_node<gd::Node3D>("%CharacterModel");
|
||||
}
|
||||
|
||||
void Player::_process(double delta [[maybe_unused]]) {
|
||||
this->anim_tree->set("parameters/Actions/Walk/Move/blend_position", this->input_directions);
|
||||
void Player::_process(double delta) {
|
||||
if(gd::Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
this->anim_tree->set("parameters/Actions/Walk/Forward/blend_amount", gd::Math::clamp(this->input_directions.y, 0.5f, 1.f));
|
||||
this->rotate_y(-this->input_directions.x * delta);
|
||||
}
|
||||
|
||||
void Player::_physics_process(double delta [[maybe_unused]]) {
|
||||
if(gd::Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
gd::Basis const &model_basis{this->model_node->get_global_basis()};
|
||||
gd::Vector3 const local_motion{this->anim_tree->get_root_motion_position()};
|
||||
gd::Vector3 const motion {
|
||||
local_motion.x * model_basis.get_column(0) +
|
||||
local_motion.y * model_basis.get_column(1) +
|
||||
local_motion.z * model_basis.get_column(2)
|
||||
local_motion.z * model_basis.get_column(2) +
|
||||
(this->is_on_floor() ? gd::Vector3{} : gd::Vector3{0.f, -1.f, 0.f})
|
||||
};
|
||||
this->set_velocity(motion / delta);
|
||||
this->move_and_slide();
|
||||
|
|
@ -45,16 +49,6 @@ void Player::_on_dir_vertical(gd::Ref<gd::InputEvent>, float value) {
|
|||
this->input_directions.y = value;
|
||||
}
|
||||
|
||||
void Player::_on_look_horizontal(gd::Ref<gd::InputEvent>, float value) {
|
||||
this->input_look.x = value;
|
||||
}
|
||||
|
||||
void Player::_on_look_vertical(gd::Ref<gd::InputEvent>, float value) {
|
||||
this->input_look.y = value;
|
||||
}
|
||||
|
||||
void Player::set_input_directions(gd::Vector2 value [[maybe_unused]]) {}
|
||||
|
||||
gd::Vector2 Player::get_input_directions() const {
|
||||
return this->input_directions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ public:
|
|||
|
||||
void _on_dir_horizontal(gd::Ref<gd::InputEvent>, float value);
|
||||
void _on_dir_vertical(gd::Ref<gd::InputEvent>, float value);
|
||||
void _on_look_horizontal(gd::Ref<gd::InputEvent>, float value);
|
||||
void _on_look_vertical(gd::Ref<gd::InputEvent>, float value);
|
||||
|
||||
void set_input_directions(gd::Vector2 value);
|
||||
gd::Vector2 get_input_directions() const;
|
||||
private:
|
||||
gd::AnimationTree *anim_tree{nullptr};
|
||||
|
|
@ -28,7 +25,6 @@ private:
|
|||
utils::PlayerInput *input{nullptr};
|
||||
gd::Node3D *model_node{nullptr};
|
||||
gd::Vector2 input_directions{};
|
||||
gd::Vector2 input_look{};
|
||||
};
|
||||
|
||||
#endif // !TR_PLAYER_HPP
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
|||
return;
|
||||
}
|
||||
utils::godot_cpp_utils_register_types();
|
||||
GDREGISTER_RUNTIME_CLASS(Player);
|
||||
GDREGISTER_CLASS(Player);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue