#deepwoken style sprint

1 messages · Page 1 of 1 (latest)

pallid kindle
#
--[[
Deepwoken style sprint                                                                                                               
]]

-- Services
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")

-- Player & Character Variables
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- Sprint Variables
local sprintSpeed = 26
local defaultSpeed = 16
local lastSprint = tick()
local sprinting = false
local sprintKeys = {
    Enum.KeyCode.W,
    Enum.KeyCode.A,
    Enum.KeyCode.S,
    Enum.KeyCode.D,
}

local ticks = {
    [Enum.KeyCode.W] = tick(),
    [Enum.KeyCode.A] = tick(),
    [Enum.KeyCode.S] = tick(),
    [Enum.KeyCode.D] = tick()
}

humanoid.WalkSpeed = defaultSpeed

-- Sprint Functions
local function SprintHandler(key, gme)
    if gme then return end

    if table.find(sprintKeys, key.KeyCode) and not sprinting then
        if tick() - ticks[key.KeyCode] <= 0.2 then
            sprinting = true
            humanoid.WalkSpeed = sprintSpeed
        else
            ticks[key.KeyCode] = tick()
        end
    end
end

local function SprintRunService()
    if sprinting then
        local oneDown = false
        for i, v in ipairs(sprintKeys) do
            if uis:IsKeyDown(v) then
                oneDown = true
            end
        end

        if not oneDown then
            sprinting = false
            humanoid.WalkSpeed = defaultSpeed
        end
    end
end

-- Sprint Events
uis.InputBegan:Connect(SprintHandler)
runService.RenderStepped:Connect(SprintRunService)```
young owl
#

👍

sick mason
#
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local moving = false
local moveTime = -math.huge

humanoid.Running:Connect(function(speed)
    if speed == 0 then
        if moving == false then return end
        moving = false
        humanoid.WalkSpeed = 16
    else
        if moving == true then return end
        moving = true
        if time() - moveTime <= 0.2 then humanoid.WalkSpeed = 26 end
        moveTime = time()
    end
end)
#

or

#
local userInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local keys = {[Enum.KeyCode.W] = false, [Enum.KeyCode.A] = false, [Enum.KeyCode.S] = false, [Enum.KeyCode.D] = false}
local keysDown = 0
local keyTime = -math.huge

userInputService.InputBegan:Connect(function(input, processed)
    if processed == true then return end
    if keys[input.KeyCode] ~= false then return end
    keys[input.KeyCode] = true
    keysDown += 1
    if keysDown ~= 1 then return end
    if time() - keyTime <= 0.2 then humanoid.WalkSpeed = 26 end
    keyTime = time()
end)

userInputService.InputEnded:Connect(function(input, processed)
    if keys[input.KeyCode] ~= true then return end
    keys[input.KeyCode] = false
    keysDown -= 1
    if keysDown ~= 0 then return end
    humanoid.WalkSpeed = 16
end)
fossil estuary
#

Lol

low crescent
sick mason
#

Os.time only updates once per second

#

Time is the time since the game started so it's a small number

low crescent
#

oh i see

icy bramble
#

deepwoken style sprint mean?

icy bramble
#

I guess you have to hit the key fast to get into sprint mode?

sick mason
icy bramble
#

ok umm , so it has a certain kind of sprint...

fossil estuary
#

if not mistaking

icy bramble
#

ah ok

mystic lodge
#

If possible is there a way this could be cross-platform.

I've always wondered how to do this for different devices, have never been able to figure out how to detect forward movement on a Analogue Stick however I suppose you could use detection for when the stick is pressed but I am interested to see if someone could detect double forward movement and such. Very nice however! (mobile + console) support is what I wanna try add

fossil estuary
#

since it uses when humanoid starts running

#

@mystic lodge

sick mason
#

But it's a little tricky to do on like touch screen you would have to drag the screen 2 times quickly

fossil estuary
sick mason
young owl
#

🦧

pallid kindle
#

tick is deprecated!!

pure wagon