feat: implemented recoil

This commit is contained in:
Sara 2025-07-19 14:26:46 +02:00
parent a7b3f97b3b
commit 58e90780d5
6 changed files with 56 additions and 7 deletions

View file

@ -88,7 +88,8 @@ void Rifle::ready() {
void Rifle::process(double delta) {
String const current{ get_anim()->get_current_animation() };
bool run_requested{ this->run_requested() };
float const progress{ float(CLAMP(get_anim()->get_current_animation_position() / get_anim()->get_current_animation_length(), 0.0, 1.0)) };
double const animation_time{ get_anim()->get_current_animation_position() };
float const progress{ float(CLAMP(animation_time / get_anim()->get_current_animation_length(), 0.0, 1.0)) };
if (current == "hip_to_aim") {
get_camera()->set_fov_factor(Math::lerp(1.f, this->ads_factor, progress));
} else if (current == "aim_to_hip") {
@ -112,6 +113,11 @@ void Rifle::process(double delta) {
stop_run_anim();
}
}
if (current == "fire_hip" || current == "fire_aim") {
double t{ animation_time / this->recoil_time };
get_camera()->recoil(Math::lerp((double)this->recoil_force, 0.0, CLAMP(t, 0.0, 1.0)) * delta);
}
}
void Rifle::_notification(int what) {
@ -147,3 +153,19 @@ void Rifle::notify_selected() {
bool Rifle::is_animating() const {
return !get_anim()->get_current_animation().is_empty() || !get_anim()->get_queue().is_empty();
}
void Rifle::set_ads_factor(float value) {
this->ads_factor = value;
}
float Rifle::get_ads_factor() const {
return this->ads_factor;
}
void Rifle::set_run_factor(float value) {
this->run_factor = value;
}
float Rifle::get_run_factor() const {
return this->run_factor;
}