1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix formula used for acceleration (#12353)

This commit is contained in:
Lars Müller 2022-09-20 10:55:51 +02:00 committed by GitHub
parent 11905a6db6
commit 1317cd12d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 16 deletions

View file

@ -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