Hello! I am attempting to create a sprinting system similar to many battlegrounds games in which if you are moving relatively forward, then you will sprint. I’ve tried many methods (such as checking the movedirection) but they all seem choppy and unresponsive, compared to other battlegrounds games. And since there is no Specific UserInput for mobile joycons, it is even harder.
Hello! I would suggest something along the lines of use ContextAction Service. I also made a little script that you might find useful if your unfamiliar with that type of service.
local ContextActionService = game:GetService("ContextActionService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local sprinting = false
local function Sprint(thing)
if sprinting then
humanoid.WalkSpeed = 30
else
humanoid.WalkSpeed = 16
end
sprinting = not sprinting
end
ContextActionService:BindAction("Sprint", Sprint, true, Enum.KeyCode.LeftShift)
I put this script in StarterPlayer>StarterCharacterScripts>LocalScript
local PlayersService = game:GetService("Players")
local RunService = game:GetService("RunService")
local Client = PlayersService.LocalPlayer
local Char = Client.Character or Client.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local Humanoid = Char:WaitForChild("Humanoid")
local WalkSpeeds = {
Sprint = 24,
Default = 16
}
RunService.RenderStepped:Connect(function()
local moveDirection = Humanoid.MoveDirection
local lookDirection = Camera.CFrame.LookVector
if lookDirection:Dot(moveDirection) > .5 then
Humanoid.WalkSpeed = WalkSpeeds.Sprint
else
Humanoid.WalkSpeed = WalkSpeeds.Default
end
end)