Limit stepheight smoothing to the stepheight and stop smoothing during jumps (#11705)

This commit is contained in:
Jude Melton-Houghton 2021-10-25 14:31:14 -04:00 committed by GitHub
parent 660e63dbae
commit 1e26e45530
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h" #include "player.h"
#include <cmath> #include <cmath>
#include "client/renderingengine.h" #include "client/renderingengine.h"
#include "client/content_cao.h"
#include "settings.h" #include "settings.h"
#include "wieldmesh.h" #include "wieldmesh.h"
#include "noise.h" // easeCurve #include "noise.h" // easeCurve
@ -341,13 +342,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
if (player->getParent()) if (player->getParent())
player_position = player->getParent()->getPosition(); player_position = player->getParent()->getPosition();
// Smooth the camera movement when the player instantly moves upward due to stepheight. // Smooth the camera movement after the player instantly moves upward due to stepheight.
// To smooth the 'not touching_ground' stepheight, smoothing is necessary when jumping // The smoothing usually continues until the camera position reaches the player position.
// or swimming (for when moving from liquid to land). float player_stepheight = player->getCAO() ? player->getCAO()->getStepHeight() : HUGE_VALF;
// Disable smoothing if climbing or flying, to avoid upwards offset of player model float upward_movement = player_position.Y - old_player_position.Y;
// when seen in 3rd person view. if (upward_movement < 0.01f || upward_movement > player_stepheight) {
bool flying = g_settings->getBool("free_move") && m_client->checkLocalPrivilege("fly"); m_stepheight_smooth_active = false;
if (player_position.Y > old_player_position.Y && !player->is_climbing && !flying) { } else if (player->touching_ground) {
m_stepheight_smooth_active = true;
}
if (m_stepheight_smooth_active) {
f32 oldy = old_player_position.Y; f32 oldy = old_player_position.Y;
f32 newy = player_position.Y; f32 newy = player_position.Y;
f32 t = std::exp(-23 * frametime); f32 t = std::exp(-23 * frametime);
@ -587,6 +591,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
const bool walking = movement_XZ && player->touching_ground; const bool walking = movement_XZ && player->touching_ground;
const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid; const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;
const bool climbing = movement_Y && player->is_climbing; const bool climbing = movement_Y && player->is_climbing;
const bool flying = g_settings->getBool("free_move")
&& m_client->checkLocalPrivilege("fly");
if ((walking || swimming || climbing) && !flying) { if ((walking || swimming || climbing) && !flying) {
// Start animation // Start animation
m_view_bobbing_state = 1; m_view_bobbing_state = 1;

@ -218,6 +218,8 @@ private:
// Camera offset // Camera offset
v3s16 m_camera_offset; v3s16 m_camera_offset;
bool m_stepheight_smooth_active = false;
// Server-sent FOV variables // Server-sent FOV variables
bool m_server_sent_fov = false; bool m_server_sent_fov = false;
f32 m_curr_fov_degrees, m_old_fov_degrees, m_target_fov_degrees; f32 m_curr_fov_degrees, m_old_fov_degrees, m_target_fov_degrees;