I’m trying to create a script to make the player slide down a slope.
I’ve tried searching for ways to do what I’m trying to do and so far have got. (This is inside another keybind connection function on the server)
local linearVelocity = Instance.new('LinearVelocity')
linearVelocity.Parent = root
linearVelocity.Name = 'SlideVelocity'
linearVelocity.Attachment0 = root:FindFirstChild('RootAttachment')
linearVelocity.MaxForce = 1000000
linearVelocity.VectorVelocity = Vector3.new(0,0,0)
linearVelocity.Visible = true
player:SetAttribute("isSliding", true)
RunService.Heartbeat:Connect(function(dt)
if player:GetAttribute("isSliding") == true then
hum.PlatformStand = true
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {character}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(part.Position, Vector3.new(0,-1000,0), rayParams)
local upVector = Vector3.yAxis
if ray then
upVector = ray.Normal
end
local rightVector = downVector:Cross(upVector)
part.CFrame = CFrame.fromMatrix(root.Position+Vector3.yAxis*5,rightVector,upVector)
local vector = Vector3.new(CFrame.fromMatrix(root.Position+Vector3.yAxis*5,rightVector,upVector):ToOrientation())
local newVector = Vector3.new(math.deg(vector.X), math.deg(vector.Y), math.deg(vector.Z))
linearVelocity.VectorVelocity = Vector3.new(
newVector.X,
-newVector.Y,
newVector.Z
)
end
end)
So far, the code is moving the character, however the character is being moved in incorrect directions. I’m assuming that is is due to the :ToOrientation but I don’t know how to fix it.
I’m open to any suggestions, including changing the linear velocity to another method, I just need some way to make this work lol.
Thanks