Get the horizontal angle between two vectors

How do I go about getting the horizontal angle between two look vectors? This is what I have so far:

		local cameraPosition: Vector3 = camera.CFrame.Position
		
		local lookVector: Vector3 = humanoidRootPart.CFrame.LookVector -- The angles x, y, and z of the player's character
		local cameraVector: Vector3 = camera.CFrame.LookVector -- The angles x, y, and z of the player's camera
		
		local yOffset: TypeUtil.double = math.pi / 2
		local zOffset: TypeUtil.double = math.pi / 2

		local verticleAngle: TypeUtil.double = yOffset + cameraVector.Y	
		local horizontalAngle: TypeUtil.double 
		
		if (isMovementEnabled) then
			TweenService:Create(rightShoulder, moveTweenInfo, {
				C0 = rightShoulderCFrame * CFrame.Angles(verticleAngle, 0, 0)
			}):Play()
		end

basically, you want to multiply the point vectors entries then add them all up (dot product) then since this value you returned could be interpreted as a cosine sine value (as you got the dot product of unit vectors, ie that means their range will be equal to -1 to 1, the same range as of cosine and or sine. so knowing that the resulteed value will be a radian you could just convert that format to the one you want by multiplying it by 180/pi (math.deg)

Thank you so much for your reply! My mind is a bit mush right now; do you mind giving an example in code?

math.deg(math.acos(vec1:Dot(vec2)))

Yes, but I just need the horizontal angle, so which two vectors would I apply the cross product on? I am doing the LookVector of the player’s HumanoidRootPart and the player’s CurrentCamera.

well then calculate the dot product but have the y entries be 0

smth like

local dot = vec1.X * vec2.X + vec1.Z * vec2.Z //0*0 = 0, so just ignore the rest
math.deg(math.acos(dot))
1 Like

So it would be like Vector3.new(x1, 0, z1):Dot(Vector3.new(x2, 0, z1))?