So earlier today I was working on a slide mechanic for my game. It took a while to get an understanding of what to do, but I've run into a couple of problems when it comes to detecting a slope that goes downward.
1. Slopes arent being detected properly. 2. The boolean value (slope) seems to randomly fire true or false once the key is pressed?
I'm thinking that I'm detecting the slope incorrectly, but need further assistance on the matter.
SCRIPT:
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
I also used: https://devforum.roblox.com/t/how-would-one-go-about-making-a-slide-mechanic/805298/2 for a guide.
