1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +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:
NeroBurner 2021-08-27 20:24:24 +02:00 committed by GitHub
parent 149d8fc8d6
commit 1d69a23ba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 98 deletions

View file

@ -998,9 +998,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
const PlayerControl &controls = player->getPlayerControl();
bool walking = false;
if (controls.up || controls.down || controls.left || controls.right ||
controls.forw_move_joystick_axis != 0.f ||
controls.sidew_move_joystick_axis != 0.f)
if (controls.movement_speed > 0.001f)
walking = true;
f32 new_speed = player->local_animation_speed;
@ -1015,9 +1013,10 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
g_settings->getBool("free_move") &&
m_client->checkLocalPrivilege("fly"))))
new_speed *= 1.5;
// slowdown speed if sneeking
// slowdown speed if sneaking
if (controls.sneak && walking)
new_speed /= 2;
new_speed *= controls.movement_speed;
if (walking && (controls.dig || controls.place)) {
new_anim = player->local_animations[3];