feat: player body now handles movement fov adjustment
This commit is contained in:
parent
b29966ccf7
commit
6c5a24e374
7 changed files with 62 additions and 43 deletions
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
void Rifle::_bind_methods() {
|
||||
BIND_PROPERTY(Variant::FLOAT, ads_factor);
|
||||
BIND_PROPERTY(Variant::FLOAT, run_factor);
|
||||
BIND_PROPERTY(Variant::FLOAT, recoil_force);
|
||||
BIND_PROPERTY(Variant::FLOAT, recoil_time);
|
||||
ClassDB::bind_method(D_METHOD("reload_full"), &self_type::reload_full);
|
||||
|
|
@ -18,13 +17,11 @@ void Rifle::_bind_methods() {
|
|||
void Rifle::queue_enter_alt() {
|
||||
get_anim()->queue("hip_to_aim");
|
||||
get_anim()->queue("aim");
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(false);
|
||||
}
|
||||
|
||||
void Rifle::queue_exit_alt() {
|
||||
get_anim()->queue("aim_to_hip");
|
||||
get_anim()->queue("hip");
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(true);
|
||||
}
|
||||
|
||||
void Rifle::queue_enter_run() {
|
||||
|
|
@ -90,12 +87,15 @@ void Rifle::on_reload() {
|
|||
void Rifle::on_animation_changed(String new_animation) {
|
||||
if (new_animation == "aim") {
|
||||
this->in_alt_mode = true;
|
||||
get_camera()->set_fov_factor(this->ads_factor);
|
||||
this->fov = this->ads_factor;
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(false);
|
||||
} else if (new_animation == "hip") {
|
||||
this->in_alt_mode = false;
|
||||
get_camera()->set_fov_factor(1.0);
|
||||
} else if (new_animation == "run") {
|
||||
get_camera()->set_fov_factor(this->run_factor);
|
||||
this->fov = 1.0;
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(true);
|
||||
}
|
||||
if (new_animation == "reload") {
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,22 +109,13 @@ void Rifle::process(double delta) {
|
|||
bool run_requested{ this->run_requested() };
|
||||
// track animation progress
|
||||
double const animation_time{ get_anim()->get_current_animation_position() };
|
||||
// percentually
|
||||
// animation progress percentually
|
||||
float const progress{ float(CLAMP(animation_time / get_anim()->get_current_animation_length(), 0.0, 1.0)) };
|
||||
// lerp the current FOV factor depending on the ongoing animation
|
||||
if (current == "hip_to_aim") {
|
||||
get_camera()->set_fov_factor(Math::lerp(1.f, this->ads_factor, progress));
|
||||
if (current == "hip_to_aim" || current == "run_to_aim") { // lerp the current FOV factor depending on the ongoing animation
|
||||
this->fov = Math::lerp(1.f, this->ads_factor, progress);
|
||||
} else if (current == "aim_to_hip") {
|
||||
get_camera()->set_fov_factor(Math::lerp(this->ads_factor, 1.f, progress));
|
||||
} else if (current == "run_to_aim") {
|
||||
get_camera()->set_fov_factor(Math::lerp(this->run_factor, this->ads_factor, progress));
|
||||
} else if (current == "hip_to_run") {
|
||||
get_camera()->set_fov_factor(Math::lerp(1.f, this->run_factor, progress));
|
||||
} else if (current == "run_to_hip") {
|
||||
get_camera()->set_fov_factor(Math::lerp(this->run_factor, 1.f, progress));
|
||||
// animation is not one of the transitory ones ( x_to_y ),
|
||||
// check if there is a request for a transitory animation
|
||||
} else if (this->request_alt_mode != this->in_alt_mode && !is_animating()) {
|
||||
this->fov = Math::lerp(this->ads_factor, 1.f, progress);
|
||||
} else if (this->request_alt_mode != this->in_alt_mode && !is_animating()) { // act on request flags that have yet to be fulfilled
|
||||
if (this->request_alt_mode) {
|
||||
queue_enter_alt();
|
||||
} else {
|
||||
|
|
@ -136,12 +127,13 @@ void Rifle::process(double delta) {
|
|||
} else if (!run_requested) {
|
||||
exit_run();
|
||||
}
|
||||
}
|
||||
// apply fire recoil
|
||||
else if (current == "fire_hip" || current == "fire_aim") {
|
||||
} else if (current == "fire_hip" || current == "fire_aim") { // apply fire recoil
|
||||
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);
|
||||
}
|
||||
if (this->fov != 1.0) {
|
||||
get_camera()->set_fov_factor(this->fov);
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::_notification(int what) {
|
||||
|
|
@ -169,11 +161,6 @@ PackedStringArray Rifle::get_configuration_warnings() const {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
bool Rifle::allows_swapping() const {
|
||||
String const current{ get_anim()->get_current_animation() };
|
||||
return !this->in_alt_mode && (current == "reload" || !is_animating());
|
||||
}
|
||||
|
||||
bool Rifle::allows_running() const {
|
||||
String const animation{ get_anim()->get_current_animation() };
|
||||
return animation == "run" && !this->request_alt_mode;
|
||||
|
|
@ -194,6 +181,10 @@ void Rifle::notify_deselected() {
|
|||
get_input()->disconnect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
|
||||
get_input()->disconnect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
|
||||
get_input()->disconnect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));
|
||||
get_camera()->set_fov_factor(1.0);
|
||||
if (HeadsUpDisplay * hud{ HeadsUpDisplay::get_singleton() }) {
|
||||
hud->set_reticle_visibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Rifle::reload_full() {
|
||||
|
|
@ -209,14 +200,6 @@ 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;
|
||||
}
|
||||
|
||||
void Rifle::set_recoil_force(float value) {
|
||||
this->recoil_force = value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue