diff --git a/modules/wave_survival/weapons/revolver.cpp b/modules/wave_survival/weapons/revolver.cpp index 5d65324a..a6aa5723 100644 --- a/modules/wave_survival/weapons/revolver.cpp +++ b/modules/wave_survival/weapons/revolver.cpp @@ -1,5 +1,6 @@ #include "revolver.h" #include "scene/animation/animation_player.h" +#include "wave_survival/player_camera.h" #include "wave_survival/player_input.h" void Revolver::_bind_methods() { @@ -14,7 +15,7 @@ void Revolver::play_equip_anim() { void Revolver::shoot() { if (!is_animating()) { this->muzzle->shoot(); - if (this->alt_requested) { + if (this->alt_active) { get_anim()->queue("fire_single"); get_anim()->queue("idle_single"); } else { @@ -42,6 +43,12 @@ void Revolver::ready() { } void Revolver::process(double delta) { + String const current{ get_anim()->get_current_animation() }; + double animation_time{ get_anim()->get_current_animation_position() }; + if (current == "fire_single" || current == "fire_double") { + 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 Revolver::_notification(int what) { diff --git a/modules/wave_survival/weapons/revolver.h b/modules/wave_survival/weapons/revolver.h index 4790ea2a..5ce58ad9 100644 --- a/modules/wave_survival/weapons/revolver.h +++ b/modules/wave_survival/weapons/revolver.h @@ -22,6 +22,9 @@ private: bool alt_requested{ false }; bool alt_active{ false }; HitscanMuzzle *muzzle{ nullptr }; + + float recoil_force{ 2.f }; + float recoil_time{ 0.06f }; }; #endif // !WEAPONS_REVOLVER_H