I’m trying to work on a sliding system and seem to be having a lot of trouble figuring out how to actually move the character along the slope
This is what I have right now, is there anything I can be doing better?
Right now the character slowly slides to the right for some reason so I’m sure I’m doing the math wrong here.
I also wonder if there’s a better method to moving the character along rather than with an AlignPosition
--Logic--
local function ContinueSlide()
local slopeCheck = rayModule.FloorRay(char, 5)
if slopeCheck == nil then module.LeaveSlide() print("No more slope") return end
local wallCheck = rayModule.FrontRay(char, 3)
if wallCheck ~= nil then module.LeaveSlide() print("Wall got in the way") return end
--If On A Slope--
local normalHorizontalComp = slopeCheck.Normal * Vector3.new(1,0,1)
if normalHorizontalComp.Magnitude > 0.01 then
--Orient Char--
slideOrien.CFrame = GetAlignedCFrame(slopeCheck)
slideOrien.Enabled = true
hum.AutoRotate = false
slidePos.Enabled = true
--Move Char--
local moveTo = slopeCheck.Position + (slopeCheck.Normal * Vector3.new(1,0,1)).Unit * slideVars.speed
local fixYRay = workspace:Raycast(moveTo, Vector3.new(0,-10,0), params)
if fixYRay ~= nil then
local pos = fixYRay.Position + Vector3.new(0,1.5,0)
slideVars.lastPos = slopeCheck.Position
slideVars.lastSlope = slopeCheck
slideVars.lastDirection = pos
slidePos.Position = pos
else
local endDistance = (slideVars.lastPos - slideVars.lastDirection).Magnitude
slidePos.Position = (hrp.CFrame + (GetAlignedCFrame(slideVars.lastSlope).LookVector * endDistance)).Position
return
end
--If Not On A Slope--
else
slidePos.Enabled = false
hum.AutoRotate = true
slideOrien.Enabled = false
end
end```