generated from Persson-dev/Godot-Xmake
add cool shadows
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
||||
#include <godot_cpp/classes/input_map.hpp>
|
||||
#include <godot_cpp/core/math.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -32,6 +33,8 @@ static constexpr float FOV_TRANSITION = 8.0f;
|
||||
static constexpr float MIN_FOV_VELOCITY = 0.5;
|
||||
static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
|
||||
|
||||
static const float AnimationBlend = 7.0;
|
||||
|
||||
void FirstPersonPlayer::_bind_methods() {}
|
||||
|
||||
FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {}
|
||||
@@ -47,6 +50,7 @@ void FirstPersonPlayer::_ready() {
|
||||
DEV_ASSERT(m_Head);
|
||||
m_Camera = Object::cast_to<Camera3D>(m_Head->find_child("Camera"));
|
||||
DEV_ASSERT(m_Camera);
|
||||
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree"));
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
|
||||
@@ -84,6 +88,8 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
|
||||
UpdateFOV(a_Delta);
|
||||
UpdateBobbing(a_Delta);
|
||||
|
||||
UpdateAnimation(a_Delta);
|
||||
|
||||
move_and_slide();
|
||||
}
|
||||
|
||||
@@ -136,4 +142,25 @@ void FirstPersonPlayer::UpdateFOV(float a_Delta) {
|
||||
m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION));
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateAnimation(float delta) {
|
||||
if (is_on_floor()) {
|
||||
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded");
|
||||
|
||||
if (get_velocity().length() > 0.2f) {
|
||||
if (m_Speed == SPRINT_SPEED) {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
UtilityFunctions::lerp(m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend));
|
||||
} else {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
UtilityFunctions::lerp(m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 0.0, delta * AnimationBlend));
|
||||
}
|
||||
} else {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
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
|
||||
Reference in New Issue
Block a user