So I’m trying to make a sliding system and I have made pretty good progress.
The script would work perfectly if it wasn’t for the fact that you can maintain yourself in the air if you slide, instead of falling down to the floor. This is a problem because I plan my game to have slopes., and if you slide before one, you will just fly over it.
This is the script:
local ts = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local crouch = Enum.KeyCode.C
local run = Enum.KeyCode.LeftShift
local running = false
local tween = ts:Create(script.Parent.HumanoidRootPart, TweenInfo.new(1.5, Enum.EasingStyle.Quart, Enum.EasingDirection.In), {Velocity = Vector3.new(0, 0, 0)})
local anim = script.Parent:WaitForChild("Humanoid"):LoadAnimation(script.slide)
uis.InputBegan:Connect(function(key_)
if key_.KeyCode == crouch then
if running == true then
anim:Play(0)
script.Parent.HumanoidRootPart.Velocity = script.Parent.HumanoidRootPart.CFrame.LookVector * 35
tween:Play()
ts:Create(script.Parent.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, -3, 0)}):Play()
ts:Create(script.camtilt, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Value = -15}):Play()
end
end
if key_.KeyCode == run then
running = true
script.Parent.Humanoid.WalkSpeed = 35
end
end)
uis.InputEnded:Connect(function(key_)
if key_.KeyCode == crouch then
anim:Stop()
tween:Cancel()
ts:Create(script.Parent.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
ts:Create(script.camtilt, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Value = 0}):Play()
end
if key_.KeyCode == run then
running = false
script.Parent.Humanoid.WalkSpeed = 18
end
end)
rs.RenderStepped:Connect(function()
if (script.Parent.HumanoidRootPart.Velocity).Magnitude < 2 then
anim:Stop()
tween:Cancel()
ts:Create(script.Parent.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
ts:Create(script.camtilt, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Value = 0}):Play()
end
game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame * CFrame.Angles(0, 0, math.rad(script.camtilt.Value))
end)
I know the problem is that I set the HumanoidRootPart’s velocity in a way that the velocity in the Y axis doesn’t change until the slide is over, I just don’t know how to make the Y velocity behave as normal while also messing with the X and Z velocity.
Thanks for the help in advance!