Hello! I have been working on this spiderman climbing system for the past few days and I have come across this roadblock. But first let me explain how the climbing system works. The A and D key rotate the character on its Z axis and only the W key makes the player go forward. Now this is when the problem arises. When switching corners I fire a ray from the head and from the root part and if both give nil then I rotate the player -90 degrees on its X axis and fire another ray then align the character to there.
However if the character attempts the turn an edge like this
it turns -90 degrees and still doesn’t find a result which ends in the player rotating rapidly or an error.
I have tried solutions like making the player go forward and firing a ray from both sides but everything gives unsatisfactory or situation dependant results.
if not ray2 and not ray then
print("yooo")
HumanoidRootPart:FindFirstChild("ClimbGyro").CFrame = HumanoidRootPart.CFrame * CFrame.Angles(math.rad(-90),0,0)
task.wait(0.05)
HumanoidRootPart:FindFirstChild("ClimbMover").Position = HumanoidRootPart:FindFirstChild("ClimbMover").Position + HumanoidRootPart.CFrame.UpVector * 4
task.wait(0.05)
local ray3 = workspace:Raycast(plr.Character:WaitForChild("HumanoidRootPart").Position, plr.Character:WaitForChild("HumanoidRootPart").CFrame.lookVector * 9,rayparam)
if ray3 then
local bodygyro = HumanoidRootPart:FindFirstChild("ClimbGyro")
local _,_,z = bodygyro.CFrame:ToOrientation()
bodygyro.CFrame = CFrame.new(ray3.Position, ray3.Position - ray3.Normal) * CFrame.Angles(0,0,z)
HumanoidRootPart:FindFirstChild("ClimbMover").Position = ray3.Position
currentsurface = ray3.Instance.Orientation
else
local rayright = workspace:Raycast(plr.Character:WaitForChild("HumanoidRootPart").Position, plr.Character:WaitForChild("HumanoidRootPart").CFrame.rightVector * 9,rayparam)
local rayleft = workspace:Raycast(plr.Character:WaitForChild("HumanoidRootPart").Position, plr.Character:WaitForChild("HumanoidRootPart").CFrame.rightVector * -9,rayparam)
HumanoidRootPart:FindFirstChild("ClimbMover").Position = HumanoidRootPart:FindFirstChild("ClimbMover").Position + HumanoidRootPart.CFrame.lookVector * 4
task.wait(0.05)
if rayright then
local bodygyro = HumanoidRootPart:FindFirstChild("ClimbGyro")
local _,_,z = bodygyro.CFrame:ToOrientation()
bodygyro.CFrame = CFrame.new(rayright.Position, rayright.Position - rayright.Normal) * CFrame.Angles(0,0,z)
HumanoidRootPart:FindFirstChild("ClimbMover").Position = rayright.Position
currentsurface = rayright.Instance.Orientation
elseif rayleft then
local bodygyro = HumanoidRootPart:FindFirstChild("ClimbGyro")
local _,_,z = bodygyro.CFrame:ToOrientation()
bodygyro.CFrame = CFrame.new(rayleft.Position, rayleft.Position - rayleft.Normal) * CFrame.Angles(0,0,z)
HumanoidRootPart:FindFirstChild("ClimbMover").Position = rayleft.Position
currentsurface = rayleft.Instance.Orientation
end
end
end