feat: implemented some controls in Player
parent
399818b342
commit
07212f2e9a
|
@ -1,14 +1,42 @@
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "utils/godot_macros.hpp"
|
#include "utils/godot_macros.hpp"
|
||||||
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
#include <godot_cpp/classes/input_event_joypad_motion.hpp>
|
||||||
|
|
||||||
void Player::_bind_methods() {
|
void Player::_bind_methods() {}
|
||||||
}
|
|
||||||
|
|
||||||
void Player::_ready() {
|
void Player::_ready() {
|
||||||
this->anim_tree = this->get_node<gd::AnimationTree>("%AnimationTree");
|
this->anim_tree = this->get_node<gd::AnimationTree>("%AnimationTree");
|
||||||
|
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");
|
this->model_node = this->get_node<gd::Node3D>("%CharacterModel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::_on_dir_horizontal(gd::Ref<gd::InputEvent>, float value) {
|
||||||
|
this->input_directions.x = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
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::_process(double delta [[maybe_unused]]) {
|
||||||
|
this->anim_tree->set("parameters/Movement/blend_position", this->input_directions);
|
||||||
|
}
|
||||||
|
|
||||||
void Player::_physics_process(double delta [[maybe_unused]]) {
|
void Player::_physics_process(double delta [[maybe_unused]]) {
|
||||||
gd::Basis const &model_basis{this->model_node->get_global_basis()};
|
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 local_motion{this->anim_tree->get_root_motion_position()};
|
||||||
|
|
|
@ -11,11 +11,19 @@ class Player : public gd::CharacterBody3D {
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual void _ready() override;
|
virtual void _ready() override;
|
||||||
|
virtual void _process(double delta) override;
|
||||||
virtual void _physics_process(double delta) override;
|
virtual void _physics_process(double delta) override;
|
||||||
|
|
||||||
|
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);
|
||||||
private:
|
private:
|
||||||
gd::AnimationTree *anim_tree{nullptr};
|
gd::AnimationTree *anim_tree{nullptr};
|
||||||
utils::PlayerInput *input{nullptr};
|
utils::PlayerInput *input{nullptr};
|
||||||
gd::Node3D *model_node{nullptr};
|
gd::Node3D *model_node{nullptr};
|
||||||
|
gd::Vector2 input_directions{};
|
||||||
|
gd::Vector2 input_look{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !TR_PLAYER_HPP
|
#endif // !TR_PLAYER_HPP
|
||||||
|
|
Loading…
Reference in New Issue