From 1317cd12d74dba4ff765d6e18b0b30cdf42002a3 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Tue, 20 Sep 2022 10:55:51 +0200 Subject: Fix formula used for acceleration (#12353) --- src/client/localplayer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/client/localplayer.cpp') diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 14be3321b..f9caf9e8b 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -292,7 +292,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, float player_stepheight = (m_cao == nullptr) ? 0.0f : (touching_ground ? m_cao->getStepHeight() : (0.2f * BS)); - v3f accel_f; + v3f accel_f(0, -gravity, 0); const v3f initial_position = position; const v3f initial_speed = m_speed; @@ -778,6 +778,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, m_speed += m_added_velocity; m_added_velocity = v3f(0.0f); + // Apply gravity (note: this is broken, but kept since this is *old* move code) + m_speed.Y -= gravity * dtime; + /* Collision detection */ @@ -1117,8 +1120,10 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, } } - float jump_height = 1.1f; // TODO: better than a magic number - v3f jump_pos = initial_position + v3f(0.0f, jump_height * BS, 0.0f); + float jumpspeed = movement_speed_jump * physics_override.jump; + float peak_dtime = jumpspeed / gravity; // at the peak of the jump v = gt <=> t = v / g + float jump_height = (jumpspeed - 0.5f * gravity * peak_dtime) * peak_dtime; // s = vt - 1/2 gt^2 + v3f jump_pos = initial_position + v3f(0.0f, jump_height, 0.0f); v3f jump_speed = initial_speed; // try at peak of jump, zero step height -- cgit v1.2.3