# Need help making this script for a sliding mechanic work

Hello, I am making a movement system and I want to include a sliding mechanic. The video below is how I want this sliding mechanic to work:

This is my current script:

``````canSlide = false

local x, y, z = hrp.CFrame:ToOrientation()

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {char}

local raycastResult = workspace:Raycast(hrp.Position, Vector3.new(0, -1, 0), raycastParams)

if raycastResult then

local newCF = CFrame.new(raycastResult.Position + raycastResult.Normal * hum.HipHeight)

newCF = newCF * CFrame.Angles(0, y, 0)

local bodyVel = Instance.new("BodyVelocity")
bodyVel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVel.Parent = hrp

if newCF.LookVector.Y < 0 then

bodyVel.Velocity =  newCF.LookVector * -100

else

bodyVel.Velocity = newCF.LookVector * 100

end
end

canSlide = true
``````

(hrp is the HumanoidRootPart)

All help is appreciated! Thanks in advance!

3 Likes

its been a while since ive seen someone use body velocity haha

Blockquote bodyVel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

try setting the maxforce to a limited number, so that the player can slide down slopes. setting maxforce to math.huge is going to make the player ignore all gravity, so thats not optimal.

and to make the sliding slow down properly, just slowly decrease the velocity like so:

``````for i = 100, 1, -1 do
bodyVel.Velocity = newCF.LookVector * i
end
``````

I shouldâ€™ve mentioned this but the script I sent doesnâ€™t even slide me which is what I wanted help on fixing, also I forgot to set the y axis in the max force vector3 to 0 but I didnt know how to slow down so ty!

also would there be a better thing to use other than body velocity? I only use this one because its the only one I know how to use.

try printing during the if statement to see if the slide is actually running

linear velocity and angular velocity are alternative methods to body velocity