generated from Persson-dev/Godot-Xmake
refactor player
This commit is contained in:
@@ -31,19 +31,13 @@ void Player::_ready() {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Player = get_node<CharacterBody3D>("Player");
|
||||
DEV_ASSERT(m_Player);
|
||||
|
||||
// we set the player to an invalid position
|
||||
m_Player->set_position({-99999, -999999, -999999});
|
||||
set_position({-99999, -999999, -999999});
|
||||
|
||||
m_Head = get_node<Node3D>("Player/Head");
|
||||
DEV_ASSERT(m_Head);
|
||||
|
||||
m_Mesh = get_node<Node3D>("Player/Armature");
|
||||
m_Mesh = get_node<Node3D>("Armature");
|
||||
DEV_ASSERT(m_Mesh);
|
||||
|
||||
m_AnimationTree = get_node<AnimationTree>("Player/AnimationTree");
|
||||
m_AnimationTree = get_node<AnimationTree>("AnimationTree");
|
||||
DEV_ASSERT(m_AnimationTree);
|
||||
}
|
||||
|
||||
@@ -51,29 +45,29 @@ void Player::_physics_process(float delta) {
|
||||
if (godot::Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
|
||||
m_Player->move_and_slide();
|
||||
move_and_slide();
|
||||
UpdateAnimation(delta);
|
||||
}
|
||||
|
||||
Vector3 Player::GetPosition() const {
|
||||
return m_Player->get_position();
|
||||
return get_position();
|
||||
}
|
||||
|
||||
void Player::SetPosition(const Vector3& a_Position) {
|
||||
m_Player->set_position(a_Position);
|
||||
set_position(a_Position);
|
||||
}
|
||||
|
||||
Vector3 Player::GetVelocity() const {
|
||||
return m_Player->get_velocity();
|
||||
return get_velocity();
|
||||
}
|
||||
|
||||
void Player::SetVelocity(const Vector3& a_Velocity) {
|
||||
m_Player->set_velocity(a_Velocity);
|
||||
set_velocity(a_Velocity);
|
||||
}
|
||||
|
||||
void Player::UpdateAnimation(float a_Delta) {
|
||||
Vector3 velocity = m_Player->get_velocity();
|
||||
float angle = m_Player->get_rotation().y;
|
||||
Vector3 velocity = get_velocity();
|
||||
float angle = get_rotation().y;
|
||||
|
||||
Vector3 direction = velocity.rotated({0, 1, 0}, -angle);
|
||||
if (direction.length() < 1.0f) {
|
||||
@@ -91,8 +85,8 @@ void Player::UpdateAnimation(float a_Delta) {
|
||||
float ratio = 0.5f - (UtilityFunctions::absf(direction.z) - UtilityFunctions::absf(direction.x)) * 0.5f;
|
||||
BlendAnimation("parameters/Movement/Walking/blend_amount", ratio, a_Delta);
|
||||
|
||||
m_AnimationTree->set("parameters/conditions/jump", !m_Player->is_on_floor() && m_Player->get_velocity().y > 0.0f);
|
||||
m_AnimationTree->set("parameters/conditions/is_on_floor", m_Player->is_on_floor());
|
||||
m_AnimationTree->set("parameters/conditions/jump", !is_on_floor() && get_velocity().y > 0.0f);
|
||||
m_AnimationTree->set("parameters/conditions/is_on_floor", is_on_floor());
|
||||
}
|
||||
|
||||
void Player::BlendAnimation(const godot::String& a_AnimationName, float a_Goal, float a_Delta) {
|
||||
@@ -117,11 +111,11 @@ void Player::SetModelVisible(bool a_Visible) {
|
||||
}
|
||||
|
||||
Vector3 Player::GetCameraRotation() const {
|
||||
return m_Player->get_rotation();
|
||||
return get_rotation();
|
||||
}
|
||||
|
||||
void Player::SetCameraRotation(const Vector3& a_Rotation) {
|
||||
m_Player->set_rotation(a_Rotation);
|
||||
set_rotation(a_Rotation);
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
|
||||
Reference in New Issue
Block a user