diff options
author | NeroBurner <pyro4hell@gmail.com> | 2021-08-27 20:24:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-27 20:24:24 +0200 |
commit | 1d69a23ba48d99b051dcf2a6be225edd7c644c7b (patch) | |
tree | ddc66759956a61e82092937897465313c65c17a0 /src/script/lua_api | |
parent | 149d8fc8d6d92e8e0d6908125ad8d3179695b1ea (diff) | |
download | minetest-1d69a23ba48d99b051dcf2a6be225edd7c644c7b.tar.gz minetest-1d69a23ba48d99b051dcf2a6be225edd7c644c7b.tar.bz2 minetest-1d69a23ba48d99b051dcf2a6be225edd7c644c7b.zip |
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>
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_localplayer.cpp | 20 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 8 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 77a692f08..9f3569ecc 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -223,16 +223,20 @@ int LuaLocalPlayer::l_get_control(lua_State *L) }; lua_createtable(L, 0, 12); - set("up", c.up); - set("down", c.down); - set("left", c.left); - set("right", c.right); - set("jump", c.jump); - set("aux1", c.aux1); + set("jump", c.jump); + set("aux1", c.aux1); set("sneak", c.sneak); - set("zoom", c.zoom); - set("dig", c.dig); + set("zoom", c.zoom); + set("dig", c.dig); set("place", c.place); + // Player movement in polar coordinates and non-binary speed + set("movement_speed", c.movement_speed); + set("movement_direction", c.movement_direction); + // Provide direction keys to ensure compatibility + set("up", player->keyPressed & (1 << 0)); // Up, down, left, and right were removed in favor of + set("down", player->keyPressed & (1 << 1)); // analog direction indicators and are therefore not + set("left", player->keyPressed & (1 << 2)); // available as booleans anymore. The corresponding values + set("right", player->keyPressed & (1 << 3)); // can still be read from the keyPressed bits though. return 1; } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index c915fa9e1..c8fa7d806 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1392,13 +1392,13 @@ int ObjectRef::l_get_player_control(lua_State *L) const PlayerControl &control = player->getPlayerControl(); lua_newtable(L); - lua_pushboolean(L, control.up); + lua_pushboolean(L, player->keyPressed & (1 << 0)); lua_setfield(L, -2, "up"); - lua_pushboolean(L, control.down); + lua_pushboolean(L, player->keyPressed & (1 << 1)); lua_setfield(L, -2, "down"); - lua_pushboolean(L, control.left); + lua_pushboolean(L, player->keyPressed & (1 << 2)); lua_setfield(L, -2, "left"); - lua_pushboolean(L, control.right); + lua_pushboolean(L, player->keyPressed & (1 << 3)); lua_setfield(L, -2, "right"); lua_pushboolean(L, control.jump); lua_setfield(L, -2, "jump"); |