diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 4c0d609c96..aee7981588 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -151,7 +151,13 @@ minetest.register_on_respawnplayer(function(player) cancelClientSprinting(player:get_player_name()) 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) + last_w_press_timer = last_w_press_timer + dtime --Get the gametime local gameTime = get_gametime() @@ -160,8 +166,22 @@ minetest.register_globalstep(function(dtime) local player = get_player_by_name(playerName) if player then 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 - 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 else players[playerName]["shouldSprint"] = false