For my slide mechanic, I wanted players to have the choice to slide down slopes, but I’ve been having
trouble correctly detecting a slope that travels down. My code so far is this:
local slope = false
local params = RaycastParams.new()
params.FilterDescendantsInstances = {workspace.Living}
params.FilterType = Enum.RaycastFilterType.Blacklist
local dist = 5
local results = workspace:Raycast(root.CFrame.p, -root.CFrame.upVector * dist, params)
if results then
local normal = results.Normal
local incline = Vector3.new(1, 0, 0):Cross(normal)
if incline.Magnitude == 0 then
incline = Vector3.new(1, 0, 0)
end
print(incline)
local angle = math.acos(Vector3.new(0, 1, 0):Dot(incline))
if angle > math.pi / 1.5 then
slope = true
end
if slope then
-- Slide Down Slope
print("Yes")
else
-- Slide For Short Distance Foward
print("No")
end
end
local dist = 5
local SLIP_ANGLE = 45
local SLIP_COS = math.cos(math.rad(SLIP_ANGLE))
local RaycastResult = workspace:Raycast(root.CFrame.p, -root.CFrame.upVector * dist, params) -- Raycast Code Here
if RaycastResult.Normal.Y < SLIP_COS then
print("Yes")
else
print("No")
end
Wouldn’t this work? I dunno about if we need math.rad