Skip to content

Commit 1e26e45

Browse files
authoredOct 25, 2021
Limit stepheight smoothing to the stepheight and stop smoothing during jumps (#11705)
1 parent 660e63d commit 1e26e45

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
 

‎src/client/camera.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "player.h"
2727
#include <cmath>
2828
#include "client/renderingengine.h"
29+
#include "client/content_cao.h"
2930
#include "settings.h"
3031
#include "wieldmesh.h"
3132
#include "noise.h" // easeCurve
@@ -341,13 +342,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
341342
if (player->getParent())
342343
player_position = player->getParent()->getPosition();
343344

344-
// Smooth the camera movement when the player instantly moves upward due to stepheight.
345-
// To smooth the 'not touching_ground' stepheight, smoothing is necessary when jumping
346-
// or swimming (for when moving from liquid to land).
347-
// Disable smoothing if climbing or flying, to avoid upwards offset of player model
348-
// when seen in 3rd person view.
349-
bool flying = g_settings->getBool("free_move") && m_client->checkLocalPrivilege("fly");
350-
if (player_position.Y > old_player_position.Y && !player->is_climbing && !flying) {
345+
// Smooth the camera movement after the player instantly moves upward due to stepheight.
346+
// The smoothing usually continues until the camera position reaches the player position.
347+
float player_stepheight = player->getCAO() ? player->getCAO()->getStepHeight() : HUGE_VALF;
348+
float upward_movement = player_position.Y - old_player_position.Y;
349+
if (upward_movement < 0.01f || upward_movement > player_stepheight) {
350+
m_stepheight_smooth_active = false;
351+
} else if (player->touching_ground) {
352+
m_stepheight_smooth_active = true;
353+
}
354+
if (m_stepheight_smooth_active) {
351355
f32 oldy = old_player_position.Y;
352356
f32 newy = player_position.Y;
353357
f32 t = std::exp(-23 * frametime);
@@ -587,6 +591,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
587591
const bool walking = movement_XZ && player->touching_ground;
588592
const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;
589593
const bool climbing = movement_Y && player->is_climbing;
594+
const bool flying = g_settings->getBool("free_move")
595+
&& m_client->checkLocalPrivilege("fly");
590596
if ((walking || swimming || climbing) && !flying) {
591597
// Start animation
592598
m_view_bobbing_state = 1;

‎src/client/camera.h

+2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class Camera
218218
// Camera offset
219219
v3s16 m_camera_offset;
220220

221+
bool m_stepheight_smooth_active = false;
222+
221223
// Server-sent FOV variables
222224
bool m_server_sent_fov = false;
223225
f32 m_curr_fov_degrees, m_old_fov_degrees, m_target_fov_degrees;

0 commit comments

Comments
 (0)
Please sign in to comment.