Hello Devs,
I am currently making a multiplayer survival type game and have a custom movement system with bhop, and sliding. It is physics based but currently my sliding is not. I would like to have it so that sliding on the ground gives you little to no boost of speed but going down slopes gives you speed like titanfall, apex legends, karlson, etc. My current movement system sets a velocity value to the players walkspeed and for my sliding currently it just takes the players current speed and multiplies it by 1.8. I have messed around with resources I have found looking on the web but have not been able to calculate the angle of slopes correctly or add velocity to my player in the way I want. Any help would be appreciated!
Sliding code:
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart
local Camera = workspace.CurrentCamera
--services
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local GuiService = game:GetService("GuiService")
--sliding varibles
local isSliding = false
local slideForce = 2
local slideCooldown = .8
local grounded = true
local justSlided = false
local slideDebounce = false
local CameraInfo = TweenInfo.new(0.3)
local CameraTweenDown = game:GetService("TweenService"):Create(player.Character.Humanoid, CameraInfo, {CameraOffset = Vector3.new(0,-2.5,1)})
local CameraTweenUp = game:GetService("TweenService"):Create(player.Character.Humanoid, CameraInfo, {CameraOffset = Vector3.new(0,0,0)})
local slidingBindable = ReplicatedStorage:WaitForChild("slidingBindable")
local stoppedSlidingBindable = ReplicatedStorage:WaitForChild("stoppedSlidingBindable")
local slidingEvent = ReplicatedStorage:WaitForChild("Sliding")
local stoppedSlidingEvent = ReplicatedStorage:WaitForChild("stoppedSliding")
local SlideAnim = humanoid:LoadAnimation(script:WaitForChild("SlideAnim"))
--sound
local slideSound = game.ReplicatedFirst.Sounds.sliding:Clone()
local landSound = game.ReplicatedFirst.Sounds.land:Clone()
slideSound.Volume = .38
slideSound.RollOffMode = Enum.RollOffMode.InverseTapered
slideSound.RollOffMaxDistance = 15
slideSound.RollOffMinDistance = 5
slideSound.TimePosition = 0
slideSound.Parent = rootPart
landSound.Volume = .4
landSound.RollOffMode = Enum.RollOffMode.InverseTapered
landSound.RollOffMaxDistance = 15
landSound.RollOffMinDistance = 5
landSound.PlaybackSpeed = .9
landSound.TimePosition = 0
landSound.Parent = rootPart
--check if grounded and handle jump sounds
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
grounded = false
end
end)
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed then
grounded = true
landSound:Play()
landSound.Ended:Connect(function()
landSound.TimePosition = 0
end)
end
end)
--actual sliding code
local function Slide(name, state, input)
if not slideDebounce then
if state == Enum.UserInputState.Begin and not isSliding and grounded and humanoid.MoveDirection.Magnitude > 0 then
isSliding = true
SlideAnim:Play()
local hVel = character.HorizontalVelocity
hVel.Value = hVel.Value * slideForce
CameraTweenDown:Play()
slidingBindable:Fire()
slidingEvent:FireServer()
slideSound:Play()
--humanoid.Sit = true
elseif state == Enum.UserInputState.Begin and not isSliding and not grounded then
isSliding = true
CameraTweenDown:Play()
SlideAnim:Play()
slidingBindable:Fire()
slidingEvent:FireServer()
slideSound:Play()
--humanoid.Sit = true
else
isSliding = false
CameraTweenUp:Play()
SlideAnim:Stop()
stoppedSlidingBindable:Fire()
stoppedSlidingEvent:FireServer()
slideSound:Pause()
slideSound.TimePosition = 0
slideDebounce = true
--humanoid.Sit = false
task.wait(slideCooldown)
slideDebounce = false
end
end
end
--binding
ContextActionService:BindAction("Sliding", Slide, true, Enum.KeyCode.LeftShift)
ContextActionService:SetPosition("Sliding", UDim2.new(-.1, 0, .5, 0))
ContextActionService:SetTitle("Sliding", "Slide")
--check if on mobile
if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
local CrouchButton = ContextActionService:GetButton("Sliding")
CrouchButton.Size = UDim2.new(.45,0,.45,0)
end