In RIVALS, The Sliding Is Very Fluid And Responsive, Making for lots a movement tricks to be done using the map’s environment, and i’d like to implement a similar sliding mechanic into my FPS game, but I’m not sure how to achieve it, and was wondering if anyone could help, whether by giving some tips or even a explanation as to how Nosniy Games made their sliding system for RIVALS.
Below is my sliding script (Which uses Roblox’s new physics character controller):
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local character = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://137581948846855"
local animator = character:FindFirstChildWhichIsA("Humanoid"):FindFirstChildWhichIsA("Animator")
local animationTrack = animator:LoadAnimation(animation)
local debounce = false
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == replicatedStorage.Keybinds:GetAttribute("Crouch") then
if debounce == false then
local controllerManager = character:FindFirstChildWhichIsA("ControllerManager")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if controllerManager.ActiveController == controllerManager:FindFirstChildWhichIsA("GroundController") then
debounce = true
local attatchment = Instance.new("Attachment")
attatchment.Name = "SlideAttatchment"
attatchment.Parent = humanoidRootPart
animationTrack:Play()
local velocity = Instance.new("LinearVelocity")
velocity.Attachment0 = attatchment
velocity.ForceLimitsEnabled = false
velocity.MaxAxesForce = Vector3.new(1, 0, 1) * 2500
velocity.VectorVelocity = Vector3.zero
if userInputService:IsKeyDown(Enum.KeyCode.W) then
velocity.VectorVelocity = humanoidRootPart.CFrame.LookVector * 100
elseif userInputService:IsKeyDown(Enum.KeyCode.A) then
velocity.VectorVelocity = humanoidRootPart.CFrame.LookVector * -100
end
velocity.Parent = humanoidRootPart
debounce = true
shared.thread = coroutine.create(function()
for count = 1, 8 do
task.wait(0.125)
velocity.VectorVelocity *= 0.75
end
end)
coroutine.resume(shared.thread)
shared.thread2 = coroutine.create(function()
task.wait(.5)
animationTrack:Stop()
velocity:Destroy()
attatchment:Destroy()
task.wait(.5)
debounce = false
end)
coroutine.resume(shared.thread2)
shared.inputBegan = userInputService.InputBegan:Connect(function(input2)
if input2.KeyCode == Enum.KeyCode.Space then
coroutine.close(shared.thread)
coroutine.close(shared.thread2)
animationTrack:Stop()
if velocity then
velocity:Destroy()
end
if attatchment then
attatchment:Destroy()
end
task.wait(.5)
debounce = false
end
end)
if debounce == false then
shared.inputBegan:Disconnect()
end
end
game:GetService("RunService").PreRender:Connect(function()
if humanoidRootPart:FindFirstChild("SlideAttatchment") then
if controllerManager.ActiveController == controllerManager:FindFirstChildWhichIsA("AirController") then
task.wait(.075)
local velocity = humanoidRootPart:FindFirstChild("Velocity")
local attatchment = humanoidRootPart:FindFirstChild("SlideAttatchment")
if velocity then
velocity:Destroy()
end
if attatchment then
attatchment:Destroy()
end
coroutine.close(shared.thread)
coroutine.close(shared.thread2)
debounce = false
animationTrack:Stop()
shared.inputBegan:Disconnect()
end
end
end)
end
end
end)