Get angle of slope

So basically I am shooting a ray down towards the floor and get the normal. How would I turn this normal into an angle? So a normal of 0, 0, 0 (Flat surface) will have an angle of 0 degree and a normal if .5, .5, 0 will return an angle of 45 degrees

math.asin(normal.Y) will give you it in radians
math.deg(math.asin(normal.Y)) will give you it in degrees

Assuming it’s a unit vector, which it will be.

3 Likes

I think the way to go is to use the Vector3 dot product between the normal and a projection of the normal onto the horizontal plane.

E.g.

local normal = Vector3.new(0.5,0.5,0).Unit

local function getHorizontalAngle(vector: Vector3)
	local axis = Vector3.yAxis
	local projection = vector - vector:Dot(axis) * axis
	
	return math.acos(vector:Dot(projection)/ (projection.Magnitude * vector.Magnitude)) 
end

local angle = getHorizontalAngle(normal)
print(angle) -- 0.7853981462831768
print(math.deg(angle)) -- 44.99999901942448