fix: run bob now lerps back to home position
This commit is contained in:
parent
b08b390c6e
commit
793391f0d3
|
@ -20,11 +20,20 @@ void PlayerCamera::update_fov() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerCamera::update_offset() {
|
void PlayerCamera::update_offset() {
|
||||||
Basis const basis{ get_basis() };
|
bool const is_running{ this->body->get_is_running() };
|
||||||
double wave{ Math::sin(this->time) };
|
if (is_running != this->was_running) {
|
||||||
Vector3 const offset{ (this->body->get_is_running() ? Vector3{ float(wave), float(Math::abs(wave)), 0 } * 0.025 : Vector3{ 0, 0, 0 }) };
|
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, {
|
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()) {
|
for (Variant child : get_children()) {
|
||||||
Node3D *child_3d{ cast_to<Node3D>(child) };
|
Node3D *child_3d{ cast_to<Node3D>(child) };
|
||||||
|
@ -43,7 +52,7 @@ void PlayerCamera::ready() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerCamera::process(double delta) {
|
void PlayerCamera::process(double delta) {
|
||||||
this->time += delta * 10.;
|
this->run_bob_time += delta * this->run_bob_frequency;
|
||||||
update_offset();
|
update_offset();
|
||||||
this->fov_factor = 1.0;
|
this->fov_factor = 1.0;
|
||||||
update_fov();
|
update_fov();
|
||||||
|
|
|
@ -26,8 +26,11 @@ private:
|
||||||
float base_fov{ 60.f };
|
float base_fov{ 60.f };
|
||||||
float fov_factor{ 1.0f };
|
float fov_factor{ 1.0f };
|
||||||
Vector3 home{ 0, 0, 0 };
|
Vector3 home{ 0, 0, 0 };
|
||||||
double time{ 0.0 };
|
|
||||||
PlayerBody *body{ nullptr };
|
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
|
#endif // !PLAYER_CAMERA_H
|
||||||
|
|
Loading…
Reference in a new issue