Allow player to run by double tapping 'W'

This commit is contained in:
Dieter44 2021-11-24 16:22:33 +01:00
parent 2127bb3ef1
commit b60c914dcd
1 changed files with 21 additions and 1 deletions

View File

@ -151,7 +151,13 @@ minetest.register_on_respawnplayer(function(player)
cancelClientSprinting(player:get_player_name()) cancelClientSprinting(player:get_player_name())
end) end)
local maximum_double_press_interval = 0.4
local last_w_press_timer = 0 -- time since ctrl.up was pressed last
local w_prev_pressed = false -- if ctrl.up was pressed the tick before
local w_double_pressed = false
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
last_w_press_timer = last_w_press_timer + dtime
--Get the gametime --Get the gametime
local gameTime = get_gametime() local gameTime = get_gametime()
@ -160,8 +166,22 @@ minetest.register_globalstep(function(dtime)
local player = get_player_by_name(playerName) local player = get_player_by_name(playerName)
if player then if player then
local ctrl = player:get_player_control() local ctrl = player:get_player_control()
-- stuff to check if player double-tapped 'W' key
if ctrl.up then
if w_prev_pressed == false then
if last_w_press_timer < maximum_double_press_interval then
w_double_pressed = true
end
last_w_press_timer = 0
w_prev_pressed = true
end
else
w_prev_pressed = false
w_double_pressed = false
end
--Check if the player should be sprinting --Check if the player should be sprinting
if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then if players[playerName]["clientSprint"] or ctrl.aux1 or w_double_pressed and ctrl.up and ctrl.sneak==false then
players[playerName]["shouldSprint"] = true players[playerName]["shouldSprint"] = true
else else
players[playerName]["shouldSprint"] = false players[playerName]["shouldSprint"] = false