local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum : Humanoid = char:WaitForChild("Humanoid")
local humrp : BasePart = char:WaitForChild("HumanoidRootPart")
local isSliding = true
local minVelocityToSlide = 15
local slideFriction = .7
local db = false
local slideAnim = hum:LoadAnimation(RS:WaitForChild("Animations").Movement.sliding)
local function slide()
if not isSliding then
local currentVelocity = char.HumanoidRootPart.Velocity
if currentVelocity.Magnitude < minVelocityToSlide then return end
isSliding = true
db = true
task.delay(.5,function()
db = false
end)
print("started")
local ogWS = hum.WalkSpeed
hum.WalkSpeed = 0
hum.HipHeight = -2
hum.AutoRotate = false
char.Head.CanCollide = false
slideAnim:Play()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
task.spawn(function()
local currFriction = 20
local onSlope = false
local slidingAttachment = Instance.new("Attachment")
slidingAttachment.Name = "SlidingAttachment"
slidingAttachment.Parent = humrp
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Enabled = true
alignOrientation.RigidityEnabled = true
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.Attachment0 = slidingAttachment
alignOrientation.Parent = humrp
humrp.AssemblyLinearVelocity = humrp.AssemblyLinearVelocity * 0.6
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(50000,0,50000)
bv.Parent = humrp
while isSliding do
local ray = workspace:Raycast(humrp.Position, Vector3.new(0,-10,0),params)
if ray then
alignOrientation.CFrame = CFrame.lookAt(Vector3.zero, humrp.AssemblyLinearVelocity)
if hum.Jump then
isSliding = false
break
end
if ray.Normal.Y < .9 then
if humrp.CFrame.LookVector.Y > 0.1 then
currFriction -= slideFriction
bv.Velocity = humrp.CFrame.LookVector * currFriction
task.wait(.03)
else
onSlope = true
currFriction = 40
bv.Velocity = humrp.CFrame.LookVector * currFriction
end
else
if onSlope then
currFriction = 20
onSlope = false
end
currFriction -= slideFriction
bv.Velocity = humrp.CFrame.LookVector * currFriction
task.wait(.05)
end
if currFriction <= 4 then
isSliding = false
break
end
else
print("no ray")
isSliding = false
break
end
game:GetService("RunService").RenderStepped:Wait()
end
char.Head.CanCollide = true
alignOrientation:Destroy()
slidingAttachment:Destroy()
bv:Destroy()
slideAnim:Stop()
hum.WalkSpeed = ogWS
hum.AutoRotate = true
hum.HipHeight = 0
end)
else
isSliding = false
end
end
UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if db then return end
if input.KeyCode == Enum.KeyCode.C then
slide()
end
end)