diff options
author | Lars Müller <34514239+appgurueu@users.noreply.github.com> | 2022-09-20 10:55:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-20 10:55:51 +0200 |
commit | 1317cd12d74dba4ff765d6e18b0b30cdf42002a3 (patch) | |
tree | 417fcd478cf89fbf4912f816bec13cf8a4b6a9c5 /src/client/localplayer.cpp | |
parent | 11905a6db65e70c84683098711ce36958968c6c3 (diff) | |
download | minetest-1317cd12d74dba4ff765d6e18b0b30cdf42002a3.tar.xz |
Fix formula used for acceleration (#12353)
Diffstat (limited to 'src/client/localplayer.cpp')
-rw-r--r-- | src/client/localplayer.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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 |