summaryrefslogtreecommitdiff
path: root/src/client/camera.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2021-10-25 14:31:14 -0400
committerGitHub <noreply@github.com>2021-10-25 20:31:14 +0200
commit1e26e4553033ebb11991721ba836e6425f556851 (patch)
treef641c6ce32dc01d692ab8b0e79e2c21c434d7e8c /src/client/camera.cpp
parent660e63dbae5901f8178b39ab40e6f770b8d7a215 (diff)
downloadminetest-1e26e4553033ebb11991721ba836e6425f556851.tar.gz
minetest-1e26e4553033ebb11991721ba836e6425f556851.tar.bz2
minetest-1e26e4553033ebb11991721ba836e6425f556851.zip
Limit stepheight smoothing to the stepheight and stop smoothing during jumps (#11705)
Diffstat (limited to 'src/client/camera.cpp')
-rw-r--r--src/client/camera.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp
index 7adcf2376..1ce92f196 100644
--- a/src/client/camera.cpp
+++ b/src/client/camera.cpp
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h"
#include <cmath>
#include "client/renderingengine.h"
+#include "client/content_cao.h"
#include "settings.h"
#include "wieldmesh.h"
#include "noise.h" // easeCurve
@@ -341,13 +342,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
if (player->getParent())
player_position = player->getParent()->getPosition();
- // Smooth the camera movement when the player instantly moves upward due to stepheight.
- // To smooth the 'not touching_ground' stepheight, smoothing is necessary when jumping
- // or swimming (for when moving from liquid to land).
- // Disable smoothing if climbing or flying, to avoid upwards offset of player model
- // when seen in 3rd person view.
- bool flying = g_settings->getBool("free_move") && m_client->checkLocalPrivilege("fly");
- if (player_position.Y > old_player_position.Y && !player->is_climbing && !flying) {
+ // Smooth the camera movement after the player instantly moves upward due to stepheight.
+ // The smoothing usually continues until the camera position reaches the player position.
+ float player_stepheight = player->getCAO() ? player->getCAO()->getStepHeight() : HUGE_VALF;
+ float upward_movement = player_position.Y - old_player_position.Y;
+ if (upward_movement < 0.01f || upward_movement > player_stepheight) {
+ m_stepheight_smooth_active = false;
+ } else if (player->touching_ground) {
+ m_stepheight_smooth_active = true;
+ }
+ if (m_stepheight_smooth_active) {
f32 oldy = old_player_position.Y;
f32 newy = player_position.Y;
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 swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;
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) {
// Start animation
m_view_bobbing_state = 1;