jump momentum as in you keep your speed through the air scaled by walk speed and a coefficient VAR?
-- Stats
local Stats = {
jumpDelay = 1,
-- walk speed
defaultSpeed = 10,
sprintSpeed = 30,
-- jump height
sprintJump = 20,
defaultJump = 10
}
-- Services
local inputService = game:GetService("UserInputService")
local players = game:GetService("Players")
-- Variables
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
-- Events
local running = false
local jumpDebounce = false
local jumpActive = true
type void = {}; local function activateJump(value: boolean): void
if value then
jumpActive = true
if not jumpDebounce then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
else
task.wait()
jumpActive = false
if jumpDebounce then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end
end
-- Sprint
inputService.InputBegan:Connect(function(input)
if (input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift) and not running then
running = true
if humanoid then
character.Humanoid.WalkSpeed = Stats.sprintSpeed
end
-- Desktop / Console
elseif (input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.ButtonX) and jumpActive then
activateJump(false)
end
end)
inputService.InputEnded:Connect(function(input)
if not inputService:IsKeyDown(Enum.KeyCode.LeftShift) and not inputService:IsKeyDown(Enum.KeyCode.RightShift) and running then
running = false
if humanoid then
character.Humanoid.WalkSpeed = Stats.defaultSpeed
end
-- Desktop / Console
elseif (input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.ButtonX) and not jumpActive then
activateJump(true)
end
end)
-- Jump
inputService.JumpRequest:Connect(function()
if jumpActive and not jumpDebounce then
jumpDebounce = true
if not jumpActive then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
if running then
humanoid.JumpHeight = Stats.sprintJump
else
humanoid.JumpHeight = Stats.defaultJump
end
task.wait(Stats.jumpDelay)
jumpDebounce = false
if jumpActive then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)
-- Mobile
if inputService.TouchEnabled then
local touchGui = player.PlayerGui:WaitForChild("TouchGui")
local touchControlFrame = touchGui:WaitForChild("TouchControlFrame")
local jumpButton = touchControlFrame:WaitForChild("JumpButton")
jumpButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch and jumpActive then
activateJump(false)
end
end)
jumpButton.InputEnded:Connect(function(input)
if input.UserInpuAtType == Enum.UserInputType.Touch and not jumpActive then
activateJump(true)
end
end)
end