Using Surface Normals for Wall Climbing

Hello,

I’ve been trying to make a wall-climbing system. I also decided to get the surface normals through raycasting to figure out which wall surface direction the player is facing when climbing. Then from there, I would change the orientation of the AlignOrientation attachment I’m using accordingly.

The problem is that the surface normal varies depending on how the wall is orientated, so I couldn’t get the exact surface of the wall.

image
(The front-facing surface normals of differently angled walls)

So I’m wondering: How would I get the specific surface of a wall (front, left, right, back) regardless of its orientated?

local newRay = workspace:Raycast(rootPart.Position, rootPart.CFrame.LookVector * 1)
local normalX = math.floor(newRay.Normal.X)
local normalZ = math.floor(newRay.Normal.Z)
					
local standardOrien = {-90, 180, 90, 0}
local axisToVectors = {
	[Vector3.new(0, 0, -1)] = standardOrien[1];
	[Vector3.new(0, 0, 1)] = standardOrien[2];
	[Vector3.new(-1, 0, 0)] = standardOrien[3];
	[Vector3.new(1, 0, 0)] = standardOrien[4];			
}
1 Like