diff --git a/modules/viscosity/player_camera.cpp b/modules/viscosity/player_camera.cpp index 3cba8fef..868431cc 100644 --- a/modules/viscosity/player_camera.cpp +++ b/modules/viscosity/player_camera.cpp @@ -18,18 +18,19 @@ void PlayerCamera::update_rotation() { double const delta{ get_process_delta_time() }; Vector3 velocity{ get_origin() - this->previous_origin }; if (velocity.length() > 0.1 && this->mouse_look_input.is_zero_approx() && this->joystick_input.is_zero_approx()) { - Vector3 forward{ -get_global_basis().get_column(2) }; + Vector3 forward{ -get_global_basis().get_column(2).normalized() }; forward.y = 0; - float x_difference{ forward.normalized().signed_angle_to({ velocity.x, 0, velocity.z }, Vector3::UP) }; - if (Math::abs(x_difference) > 0.1f) { - this->rotate(Vector3::UP, CLAMP(x_difference * delta, -1.f * delta, 1.f * delta)); - } - forward = -get_global_basis().get_column(2) + Vector3(0, .2, 0); - float y_difference{ forward.signed_angle_to(velocity, get_global_basis().get_column(0)) }; - if (Math::abs(y_difference) > 0.1) { - this->rotate_object_local(Vector3::RIGHT, CLAMP(y_difference, -0.002, 0.002)); - } + float const x_difference{ forward.signed_angle_to(Vector3{ velocity.x, 0, velocity.z }.normalized(), Vector3::UP) }; + this->global_rotate(Vector3::UP, CLAMP(Math::pow(x_difference, 3.f), -2.f, 2.f) * delta); + + forward = -get_global_basis().get_column(2).normalized(); + forward = Vector3(velocity.x, forward.y, velocity.z).normalized(); + Vector3 left{ get_global_basis().get_column(0) }; + left.y = 0.f; + + float const y_difference{ forward.signed_angle_to(velocity.normalized(), left.normalized()) }; + this->rotate_object_local(Vector3::RIGHT, CLAMP(Math::pow(y_difference, 3.f), -2.f, 2.f) * delta); } this->mouse_look_input *= 0.0001f; this->rotate(Vector3::DOWN, this->mouse_look_input.x * this->mouse_sensitivity - this->joystick_input.x * delta * this->joystick_sensitivity); @@ -50,9 +51,7 @@ void PlayerCamera::update_position() { this->ray.to = target; PhysicsDirectSpaceState3D::RayResult result{}; if (get_world_3d()->get_direct_space_state()->intersect_ray(this->ray, result)) { - distance = origin.distance_to(result.position) - (2.0 - Math::abs(direction.dot(result.normal))); - } else { - distance -= 1.f; + distance = origin.distance_to(result.position) - (1.0 - Math::abs(direction.dot(result.normal))); } look_at_from_position(origin + direction * MAX(distance, 0.4f), origin); this->previous_origin = origin;