I’m trying to make a collision system where upon hitting a wall head-on, the player stops in their tracks, but if they hit it at an angle, they slide along it. Like the image sequence shown here:
I’m just trying to snap the player in the direction of the wall, so they can keep moving forward in that direction themselves.
Right now, I’m using a raycast, and I’m able to judge the angle at which you hit the wall at, I’m just having trouble snapping the player in the desired direction. Here’s a bit of what I have right now:
local MidFrontHit, MidFrontPos, MidFrontNor = Raycast(hrp.Position, hrp.CFrame.LookVector * 1, 4)
if MidFrontHit then
local dot = hrp.CFrame.LookVector:Dot(MidFrontNor)
if dot < -0.6 or dot > 0.6 then --If head-on collision
FrontCollision(MidFrontHit) --Front collision function
else
--Snap to rotation along wall
end
else
FrontCollide = false
end
What should I do to rotate the HumanoidRootPart’s CFrame correctly? I have it in place so that you rotate on slopes as well, so it’d have to play in accordance to that.