feat: implemented recoil
This commit is contained in:
parent
a7b3f97b3b
commit
58e90780d5
6 changed files with 56 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@ public:
|
|||
virtual void notify_selected() override;
|
||||
bool is_animating() const;
|
||||
|
||||
void set_recoil_radians(float value);
|
||||
float get_recoil_radians() const;
|
||||
void set_ads_factor(float value);
|
||||
float get_ads_factor() const;
|
||||
void set_run_factor(float value);
|
||||
float get_run_factor() const;
|
||||
|
||||
private:
|
||||
float ads_factor{ 0.5f };
|
||||
float run_factor{ 1.5f };
|
||||
|
|
@ -37,6 +44,9 @@ private:
|
|||
bool in_alt_mode{ false };
|
||||
bool running{ false };
|
||||
|
||||
float recoil_force{ 3.f };
|
||||
float recoil_time{ 0.05f };
|
||||
|
||||
HitscanMuzzle *muzzle{ nullptr };
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue