generated from Persson-dev/Godot-Xmake
69 lines
2.0 KiB
C++
69 lines
2.0 KiB
C++
#include "Player.h"
|
|
|
|
#include <godot_cpp/classes/engine.hpp>
|
|
#include <godot_cpp/classes/input.hpp>
|
|
#include <godot_cpp/classes/input_map.hpp>
|
|
#include <godot_cpp/core/class_db.hpp>
|
|
#include <godot_cpp/variant/utility_functions.hpp>
|
|
|
|
static const float WalkSpeed = 2.0;
|
|
static const float RunSpeed = 5.0;
|
|
static const float JumpStrength = 15.0;
|
|
static const float Gravity = 50.0;
|
|
|
|
static const float LerpValue = 0.15;
|
|
static const float AnimationBlend = 7.0;
|
|
|
|
namespace blitz {
|
|
|
|
void Player::_bind_methods() {}
|
|
|
|
Player::Player() {}
|
|
Player::~Player() {}
|
|
|
|
void Player::_ready() {
|
|
godot::InputMap::get_singleton()->load_from_project_settings();
|
|
m_PlayerMesh = Object::cast_to<godot::Node3D>(find_child("Mesh"));
|
|
m_AnimationTree = Object::cast_to<godot::AnimationTree>(find_child("AnimationTree"));
|
|
DEV_ASSERT(m_PlayerMesh);
|
|
DEV_ASSERT(m_AnimationTree);
|
|
|
|
apply_floor_snap();
|
|
animate(0);
|
|
}
|
|
|
|
void Player::_physics_process(float delta) {
|
|
if (godot::Engine::get_singleton()->is_editor_hint())
|
|
return;
|
|
|
|
|
|
apply_floor_snap();
|
|
move_and_slide();
|
|
animate(delta);
|
|
}
|
|
|
|
void Player::animate(float delta) {
|
|
if (is_on_floor()) {
|
|
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded");
|
|
|
|
if (get_velocity().length() > 0) {
|
|
if (m_Speed == RunSpeed) {
|
|
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
|
godot::UtilityFunctions::lerp(
|
|
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend));
|
|
} else {
|
|
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
|
godot::UtilityFunctions::lerp(
|
|
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 0.0, delta * AnimationBlend));
|
|
}
|
|
} else {
|
|
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
|
godot::UtilityFunctions::lerp(
|
|
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), -1.0, delta * AnimationBlend));
|
|
}
|
|
} else {
|
|
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "air");
|
|
}
|
|
}
|
|
} // namespace blitz
|