mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Joystick sensitivity for player movement (#11262)
This commit deprecates the forward, backward, left, and right binary inputs currently used for player movement in the PlayerControl struct. In their place, it adds the movement_speed and movement_direction values, which represents the player movement is a polar coordinate system. movement_speed is a scalar from 0.0 to 1.0. movement_direction is an angle from 0 to +-Pi: FWD 0 _ LFT / \ RGT -Pi/2 | | +Pi/2 \_/ +-Pi BCK Boolean movement bits will still be set for server telegrams and Lua script invocations to provide full backward compatibility. When generating these values from an analog input, a direction is considered active when it is 22.5 degrees away from either orthogonal axis. Co-authored-by: Markus Koch <markus@notsyncing.net> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
149d8fc8d6
commit
1d69a23ba4
10 changed files with 137 additions and 98 deletions
|
@ -566,23 +566,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
|||
}
|
||||
}
|
||||
|
||||
if (control.up)
|
||||
speedH += v3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
if (control.down)
|
||||
speedH -= v3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
if (!control.up && !control.down)
|
||||
speedH -= v3f(0.0f, 0.0f, 1.0f) * (control.forw_move_joystick_axis / 32767.f);
|
||||
|
||||
if (control.left)
|
||||
speedH += v3f(-1.0f, 0.0f, 0.0f);
|
||||
|
||||
if (control.right)
|
||||
speedH += v3f(1.0f, 0.0f, 0.0f);
|
||||
|
||||
if (!control.left && !control.right)
|
||||
speedH += v3f(1.0f, 0.0f, 0.0f) * (control.sidew_move_joystick_axis / 32767.f);
|
||||
speedH = v3f(sin(control.movement_direction), 0.0f, cos(control.movement_direction));
|
||||
|
||||
if (m_autojump) {
|
||||
// release autojump after a given time
|
||||
|
@ -639,6 +623,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
|||
else
|
||||
speedH = speedH.normalize() * movement_speed_walk;
|
||||
|
||||
speedH *= control.movement_speed; /* Apply analog input */
|
||||
|
||||
// Acceleration increase
|
||||
f32 incH = 0.0f; // Horizontal (X, Z)
|
||||
f32 incV = 0.0f; // Vertical (Y)
|
||||
|
@ -1106,9 +1092,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
|
|||
if (m_autojump)
|
||||
return;
|
||||
|
||||
bool control_forward = control.up ||
|
||||
(!control.up && !control.down &&
|
||||
control.forw_move_joystick_axis < -0.05f);
|
||||
bool control_forward = keyPressed & (1 << 0);
|
||||
|
||||
bool could_autojump =
|
||||
m_can_jump && !control.jump && !control.sneak && control_forward;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue