Find dot product angle relative to threshold

Hello, rather simple question:

If I have the following example code which calculates basic line of sight from a dummy to a player, what is a good way to convert the dot product’s threshold (0.4 in the example below) to degrees/radians and back?

Are there any charts online that people have made for such a thing?

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		while task.wait() do
			local dummyUnit = (character.Head.Position - workspace.Dummy.Head.Position).Unit
			local dummyLookVector = workspace.Dummy.Head.CFrame.LookVector
			local dotProduct = dummyUnit:Dot(dummyLookVector)

			if dotProduct > 0.4 then -- what is the maximum angle here?
				print("in line of sight")
			else
				print("not in line of sight")
			end
		end		
	end)
end)

math.acos converts dot product to radians
math.cos converts radians to a dot product

note: these are expensive trig functions so don’t spam them everywhere

1 Like

if dotProduct > math.cos(math.rad(30)) then

Would check if the angle was less than 30 degrees (i.e. the whole cone is 60 degrees).

1 Like