diff --git a/modules/wave_survival/player_camera.cpp b/modules/wave_survival/player_camera.cpp index cda59c2e..92ed0c34 100644 --- a/modules/wave_survival/player_camera.cpp +++ b/modules/wave_survival/player_camera.cpp @@ -20,11 +20,20 @@ void PlayerCamera::update_fov() { } void PlayerCamera::update_offset() { - Basis const basis{ get_basis() }; - double wave{ Math::sin(this->time) }; - Vector3 const offset{ (this->body->get_is_running() ? Vector3{ float(wave), float(Math::abs(wave)), 0 } * 0.025 : Vector3{ 0, 0, 0 }) }; + bool const is_running{ this->body->get_is_running() }; + if (is_running != this->was_running) { + this->was_running = is_running; + this->run_bob_time = 0.0; + } + double wave{ Math::sin(this->run_bob_time) }; + Vector3 offset{ Vector3{ float(wave), float(Math::abs(wave)), 0 } * this->run_bob_amplitude }; + if (!is_running) { + this->run_bob_time = MIN(this->run_bob_time, this->run_bob_amplitude); + offset = offset.lerp(Vector3(), this->run_bob_time / this->run_bob_amplitude); + } GETSET(position, { - position = this->home + basis.get_column(0) * offset.x + basis.get_column(1) * offset.y; + Basis const basis{ get_basis() }; + position = this->home + basis.get_column(0) * offset.x + basis.get_column(1) * offset.y * 5.0; }); for (Variant child : get_children()) { Node3D *child_3d{ cast_to(child) }; @@ -43,7 +52,7 @@ void PlayerCamera::ready() { } void PlayerCamera::process(double delta) { - this->time += delta * 10.; + this->run_bob_time += delta * this->run_bob_frequency; update_offset(); this->fov_factor = 1.0; update_fov(); diff --git a/modules/wave_survival/player_camera.h b/modules/wave_survival/player_camera.h index 1489d5d1..a5a3ce94 100644 --- a/modules/wave_survival/player_camera.h +++ b/modules/wave_survival/player_camera.h @@ -26,8 +26,11 @@ private: float base_fov{ 60.f }; float fov_factor{ 1.0f }; Vector3 home{ 0, 0, 0 }; - double time{ 0.0 }; PlayerBody *body{ nullptr }; + bool was_running{ false }; + double run_bob_time{ 0.0 }; + double run_bob_amplitude{ 0.025 }; + double run_bob_frequency{ 10.0 }; }; #endif // !PLAYER_CAMERA_H