trenches/src/player.cpp

23 lines
744 B
C++
Raw Normal View History

2024-11-26 23:41:39 +00:00
#include "player.hpp"
#include "utils/godot_macros.hpp"
void Player::_bind_methods() {
}
void Player::_ready() {
this->anim_tree = this->get_node<gd::AnimationTree>("%AnimationTree");
this->model_node = this->get_node<gd::Node3D>("%CharacterModel");
}
void Player::_physics_process(double delta [[maybe_unused]]) {
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)
};
this->set_velocity(motion / delta);
this->move_and_slide();
}